feat(@adobe/es-modules-middleware): new type definition (#43156)

- type definition
- tests for different usage scenarios (Karma config for webcomponents
and Express middleware)

https://github.com/adobe/es-modules-middleware
https://github.com/adobe/es-modules-middleware#usage

Thanks!
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz) 2020-04-01 00:38:28 +02:00 committed by GitHub
parent bcba5e2eaf
commit 29563739dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,30 @@
// Type definitions for @adobe/es-modules-middleware 1.1
// Project: https://github.com/adobe/es-modules-middleware#readme
// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.2
import 'karma';
import { NextHandleFunction } from 'connect';
declare module 'karma' {
interface ConfigOptions {
/**
* used in Karma to aid in testing es-modules in the browser
* see {@link https://github.com/adobe/es-modules-middleware}
*/
esModulesMiddleware?: MiddlewareOptions;
}
}
/**
* used as a connect middleware by providing it with a map of url base path to file system path from which to serve files.
* Any files served through the middleware will be processed to resolve import/export paths properly.
*/
export interface MiddlewareOptions {
/** a map of url base path to file system path from which to serve files */
paths: {
[path: string]: string;
};
}
export function middleware(options?: MiddlewareOptions): NextHandleFunction;

View File

@ -0,0 +1,19 @@
/// <reference types="node" />
import esModuleMiddleware = require('@adobe/es-modules-middleware');
import express = require('express');
import path = require('path');
const app = express();
const port = 3000;
const rootPath = path.resolve(__dirname);
app.use(
esModuleMiddleware.middleware({
paths: {
'/node_modules': path.join(rootPath, 'node_modules'),
},
}),
);
app.listen(port, () => console.log(`Example app listening on port ${port}!`));

View File

@ -0,0 +1,39 @@
/// <reference types="node" />
import path = require('path');
import karma = require('karma');
module.exports = (config: karma.Config) => {
config.set({
// @adobe/es-modules-middleware
esModulesMiddleware: {
paths: {
'/': __dirname,
'/node_modules': path.join(__dirname, 'node_modules'),
},
},
// other
basePath: '.',
plugins: ['karma-*', require('@adobe/es-modules-middleware')],
frameworks: ['mocha', 'chai', 'sinon', 'web-components'],
middleware: ['es-modules'],
files: [
{
pattern: '**/*.test.html',
watched: false,
included: false,
served: true,
},
{
pattern: '**/test/*.js',
watched: true,
included: false,
served: false,
},
],
proxies: {
'/node_modules/': '/base/node_modules/',
},
reporters: ['mocha'],
});
};

View File

@ -0,0 +1,29 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"@adobe/es-modules-middleware": [
"adobe__es-modules-middleware"
]
}
},
"files": [
"index.d.ts",
"test/express.tests.ts",
"test/karma.tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }