first commit

This commit is contained in:
jefferyzhao
2025-07-31 17:44:12 +08:00
commit b9bdc8598b
42390 changed files with 4467935 additions and 0 deletions

58
node_modules/pnp-webpack-plugin/README.md generated vendored Normal file
View File

@ -0,0 +1,58 @@
# <img src="https://raw.githubusercontent.com/webpack/media/master/logo/icon-square-small.png" height="40" align="right" /> [Plug'n'Play](https://github.com/yarnpkg/rfcs/pull/101) resolver for Webpack
[![npm version](https://img.shields.io/npm/v/pnp-webpack-plugin.svg)](https://www.npmjs.com/package/pnp-webpack-plugin)
[![node version](https://img.shields.io/node/v/pnp-webpack-plugin.svg)](https://www.npmjs.com/package/pnp-webpack-plugin)
*This plugin is also available for Jest ([jest-pnp-resolver](https://github.com/arcanis/jest-pnp-resolver)), Rollup ([rollup-plugin-pnp-resolve](https://github.com/arcanis/rollup-plugin-pnp-resolve)), and TypeScript ([ts-pnp](https://github.com/arcanis/ts-pnp))*
## Installation
```
yarn add -D pnp-webpack-plugin
```
## Usage
Simply add the plugin to both the `resolver` and `resolveLoader`:
```js
const PnpWebpackPlugin = require(`pnp-webpack-plugin`);
module.exports = {
resolve: {
plugins: [
PnpWebpackPlugin,
],
},
resolveLoader: {
plugins: [
PnpWebpackPlugin.moduleLoader(module),
],
},
};
```
The `resolve` entry will take care of correctly resolving the dependencies required by your program, and the `resolveLoader` entry will help Webpack find the location of the loaders on the disk. Note that in this case, all loaders will be resolved relative to the package containing your configuration.
In case part of your configuration comes from third-party packages that use their own loaders, make sure they use `require.resolve` - this will ensure that the resolution process is portable accross environments (including when Plug'n'Play isn't enabled), and prevent it from relying on undefined behaviors:
```js
module.exports = {
module: {
rules: [{
test: /\.js$/,
loader: require.resolve('babel-loader'),
}]
},
};
```
## License (MIT)
> **Copyright © 2016 Maël Nison**
>
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0
node_modules/pnp-webpack-plugin/fixtures/file.js generated vendored Normal file
View File

0
node_modules/pnp-webpack-plugin/fixtures/index.js generated vendored Normal file
View File

92
node_modules/pnp-webpack-plugin/index.js generated vendored Normal file
View File

@ -0,0 +1,92 @@
const path = require(`path`);
const {resolveModuleName} = require(`ts-pnp`);
const {makeResolver} = require('./resolver');
function nothing() {
// ¯\_(ツ)_/¯
}
function getModuleLocator(module, pnpapi) {
const moduleLocation = typeof module === `string`
? module
: module.filename;
if (!moduleLocation)
throw new Error(`The specified module doesn't seem to exist on the filesystem`);
const moduleLocator = pnpapi.findPackageLocator(moduleLocation);
if (!moduleLocator)
throw new Error(`the specified module doesn't seem to be part of the dependency tree`);
return moduleLocator;
}
function getDependencyLocator(sourceLocator, name, pnpapi) {
const {packageDependencies} = pnpapi.getPackageInformation(sourceLocator);
const reference = packageDependencies.get(name);
return {name, reference};
}
module.exports = process.versions.pnp ? {
apply: makeResolver({pnpapi: require(`pnpapi`)}),
} : {
apply: nothing,
};
module.exports.makePlugin = (locator, filter) => process.versions.pnp ? {
apply: makeResolver({sourceLocator: locator, filter, pnpapi: require(`pnpapi`)}),
} : {
apply: nothing,
};
module.exports.moduleLoader = (module) => {
if (process.versions.pnp) {
const pnpapi = require(`pnpapi`);
return {
apply: makeResolver({
sourceLocator: getModuleLocator(module, pnpapi),
pnpapi,
}),
};
}
return {
apply: nothing,
};
};
module.exports.topLevelLoader = process.versions.pnp ? {
apply: makeResolver({sourceLocator: {name: null, reference: null}, pnpapi: require(`pnpapi`)}),
} : {
apply: nothing,
};
module.exports.bind = (filter, module, dependency) => {
if (process.versions.pnp) {
const pnpapi = require(`pnpapi`);
return {
apply: makeResolver({
sourceLocator: dependency
? getDependencyLocator(getModuleLocator(module, pnpapi), dependency, pnpapi)
: getModuleLocator(module, pnpapi),
filter,
pnpapi,
}),
};
}
return {
apply: nothing,
};
};
module.exports.tsLoaderOptions = (options = {}) => process.versions.pnp ? Object.assign({}, options, {
resolveModuleName: resolveModuleName,
resolveTypeReferenceDirective: resolveModuleName,
}) : options;
module.exports.forkTsCheckerOptions = (options = {}) => process.versions.pnp ? Object.assign({}, options, {
resolveModuleNameModule: require.resolve(`./ts`),
resolveTypeReferenceDirectiveModule: require.resolve(`./ts`),
}) : options;

63
node_modules/pnp-webpack-plugin/index.test.js generated vendored Normal file
View File

@ -0,0 +1,63 @@
const path = require(`path`);
let PnpWebpackPlugin = require(`./index`);
function makeResolver(resolverPlugins, options = {}) {
const {
NodeJsInputFileSystem,
CachedInputFileSystem,
ResolverFactory
} = require('enhanced-resolve');
const resolver = ResolverFactory.createResolver({
fileSystem: new CachedInputFileSystem(new NodeJsInputFileSystem(), 4000),
extensions: ['.js', '.json'],
... options,
});
for (const {apply} of resolverPlugins)
apply(resolver);
return resolver;
}
function makeRequest(resolver, request, issuer) {
return new Promise((resolve, reject) => {
resolver.resolve({}, issuer, request, {}, (err, filepath) => {
if (err) {
reject(err);
} else {
resolve(filepath);
}
});
});
}
describe(`Regular Plugin`, () => {
it(`should correctly resolve a relative require`, async () => {
const resolver = makeResolver([PnpWebpackPlugin]);
const resolution = await makeRequest(resolver, `./index.js`, __dirname);
expect(resolution).toEqual(path.normalize(`${__dirname}/index.js`));
});
it(`shouldn't prevent the 'extensions' option from working`, async () => {
const resolver = makeResolver([PnpWebpackPlugin]);
const resolution = await makeRequest(resolver, `./index`, __dirname);
expect(resolution).toEqual(path.normalize(`${__dirname}/index.js`));
});
it(`shouldn't prevent the 'alias' option from working`, async () => {
const resolver = makeResolver([PnpWebpackPlugin], {alias: {[`foo`]: `./fixtures/index.js`}});
const resolution = await makeRequest(resolver, `foo`, __dirname);
expect(resolution).toEqual(path.normalize(`${__dirname}/fixtures/index.js`));
});
it(`shouldn't prevent the 'modules' option from working`, async () => {
const resolver = makeResolver([PnpWebpackPlugin], {modules: [`./fixtures`]});
const resolution = await makeRequest(resolver, `file`, __dirname);
expect(resolution).toEqual(path.normalize(`${__dirname}/fixtures/file.js`));
});
});

4
node_modules/pnp-webpack-plugin/jest.config.js generated vendored Normal file
View File

@ -0,0 +1,4 @@
module.exports = {
resolver: require.resolve(`jest-pnp-resolver`),
testEnvironment: `node`,
};

36
node_modules/pnp-webpack-plugin/package.json generated vendored Normal file
View File

@ -0,0 +1,36 @@
{
"name": "pnp-webpack-plugin",
"version": "1.7.0",
"description": "plug'n'play resolver for Webpack",
"license": "MIT",
"engines": {
"node": ">=6"
},
"homepage": "https://github.com/arcanis/pnp-webpack-plugin",
"bugs": {
"url": "https://github.com/arcanis/pnp-webpack-plugin/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/arcanis/pnp-webpack-plugin.git"
},
"keywords": [
"webpack",
"yarn",
"plugnplay",
"pnp"
],
"dependencies": {
"ts-pnp": "^1.1.6"
},
"devDependencies": {
"enhanced-resolve": "^4.1.0",
"jest": "^23.6.0",
"jest-environment-node": "^23.4.0",
"jest-pnp-resolver": "^1.0.1",
"source-map": "^0.7.3"
},
"installConfig": {
"pnp": true
}
}

117
node_modules/pnp-webpack-plugin/resolver.js generated vendored Normal file
View File

@ -0,0 +1,117 @@
const path = require(`path`);
/**
* return source path given a locator
* @param {*} sourceLocator
* @returns
*/
function getSourceLocation(sourceLocator, pnpapi) {
if (!sourceLocator) return null;
const sourceInformation = pnpapi.getPackageInformation(sourceLocator);
if (!sourceInformation)
throw new Error(`Couldn't find the package to use as resolution source`);
if (!sourceInformation.packageLocation)
throw new Error(
`The package to use as resolution source seem to not have been installed - maybe it's a devDependency not installed in prod?`
);
return sourceInformation.packageLocation.replace(/\/?$/, `/`);
}
/**
*
* @param {*} sourceLocator
* @param {*} filter
* @returns
*/
function makeResolver(opts) {
const { sourceLocator, filter, pnpapi } = opts || {};
const sourceLocation = getSourceLocation(sourceLocator, pnpapi);
return (resolver) => {
const BACKWARD_PATH = /^\.\.([\\\/]|$)/;
const resolvedHook = resolver.ensureHook(`resolve`);
// Prevents the SymlinkPlugin from kicking in. We need the symlinks to be preserved because that's how we deal with peer dependencies ambiguities.
resolver.getHook(`file`).intercept({
register: (tapInfo) => {
return tapInfo.name !== `SymlinkPlugin`
? tapInfo
: Object.assign({}, tapInfo, {
fn: (request, resolveContext, callback) => {
callback();
},
});
},
});
resolver
.getHook(`after-module`)
.tapAsync(`PnpResolver`, (request, resolveContext, callback) => {
// rethrow pnp errors if we have any for this request
return callback(
resolveContext.pnpErrors &&
resolveContext.pnpErrors.get(request.context.issuer)
);
});
// Register a plugin that will resolve bare imports into the package location on the filesystem before leaving the rest of the resolution to Webpack
resolver
.getHook(`before-module`)
.tapAsync(`PnpResolver`, (requestContext, resolveContext, callback) => {
let request = requestContext.request;
let issuer = requestContext.context.issuer;
// When using require.context, issuer seems to be false (cf https://github.com/webpack/webpack-dev-server/blob/d0725c98fb752d8c0b1e8c9067e526e22b5f5134/client-src/default/index.js#L94)
if (!issuer) {
issuer = `${requestContext.path}/`;
// We only support issuer when they're absolute paths. I'm not sure the opposite can ever happen, but better check here.
} else if (!path.isAbsolute(issuer)) {
throw new Error(
`Cannot successfully resolve this dependency - issuer not supported (${issuer})`
);
}
if (filter) {
const relative = path.relative(filter, issuer);
if (path.isAbsolute(relative) || BACKWARD_PATH.test(relative)) {
return callback(null);
}
}
let resolutionIssuer = sourceLocation || issuer;
let resolution;
try {
resolution = pnpapi.resolveToUnqualified(request, resolutionIssuer, {
considerBuiltins: false,
});
} catch (error) {
if (resolveContext.missingDependencies)
resolveContext.missingDependencies.add(requestContext.path);
if (resolveContext.log) resolveContext.log(error.message);
resolveContext.pnpErrors = resolveContext.pnpErrors || new Map();
resolveContext.pnpErrors.set(issuer, error);
return callback();
}
resolver.doResolve(
resolvedHook,
Object.assign({}, requestContext, {
request: resolution,
}),
null,
resolveContext,
callback
);
});
};
}
module.exports.makeResolver = makeResolver;

9
node_modules/pnp-webpack-plugin/ts.js generated vendored Normal file
View File

@ -0,0 +1,9 @@
const {resolveModuleName} = require(`ts-pnp`);
exports.resolveModuleName = (typescript, moduleName, containingFile, compilerOptions, resolutionHost) => {
return resolveModuleName(moduleName, containingFile, compilerOptions, resolutionHost, typescript.resolveModuleName);
};
exports.resolveTypeReferenceDirective = (typescript, moduleName, containingFile, compilerOptions, resolutionHost) => {
return resolveModuleName(moduleName, containingFile, compilerOptions, resolutionHost, typescript.resolveTypeReferenceDirective);
};