Add types/tests for webpack-virtual-modules (#37025)

* Add types/tests for webpack-virtual-modules

* Set minimun typescript to match webpack's
This commit is contained in:
Avi Vahl 2019-07-22 23:21:20 +03:00 committed by Wesley Wigham
parent fb3854f2c0
commit 2aceb916d9
4 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,28 @@
// Type definitions for webpack-virtual-modules 0.1
// Project: https://github.com/sysgears/webpack-virtual-modules
// Definitions by: Avi Vahl <https://github.com/AviVahl>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import webpack = require('webpack');
/**
* Plugin that allows dynamic generation of in-memory virtual modules for JavaScript builds
* created with webpack.
*/
declare class VirtualModulesPlugin {
constructor(modules?: Record<string, string>);
/**
* Attaches necessary hooks, in particular, `afterEnvironment`, `afterResolvers`, and `watchRun` hooks,
* to ensure that the virtual files are added dynamically.
*/
apply(compiler: webpack.Compiler): void;
/**
* Writes a static or dynamic virtual module to a path.
*/
writeModule(filePath: string, fileContents: string): void;
}
export = VirtualModulesPlugin;

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"webpack-virtual-modules-tests.ts"
]
}

View File

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

View File

@ -0,0 +1,13 @@
import webpack = require('webpack');
import VirtualModulesPlugin = require('webpack-virtual-modules');
const virtualModules = new VirtualModulesPlugin({
'node_modules/module-foo.js': 'module.exports = { foo: "foo" };',
'node_modules/module-bar.js': 'module.exports = { bar: "bar" };',
});
virtualModules.writeModule('node_modules/module-foo.js', 'module.exports = { foo: "foo" };');
webpack({
plugins: [virtualModules],
});