@rslib/core 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/entryModuleLoader.js +1 -1
- package/dist/index.js +170 -469
- package/dist/libCssExtractLoader.js +2 -9
- package/dist-types/asset/assetConfig.d.ts +3 -0
- package/dist-types/config.d.ts +3 -2
- package/dist-types/css/cssConfig.d.ts +1 -1
- package/dist-types/package.json +1 -0
- package/dist-types/types/{config/index.d.ts → config.d.ts} +21 -4
- package/dist-types/types/utils.d.ts +1 -0
- package/dist-types/utils/helper.d.ts +4 -2
- package/package.json +7 -6
package/dist/index.js
CHANGED
|
@@ -8,10 +8,7 @@ import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core__ from "@rsbuild/core";
|
|
|
8
8
|
import * as __WEBPACK_EXTERNAL_MODULE_tinyglobby__ from "tinyglobby";
|
|
9
9
|
import * as __WEBPACK_EXTERNAL_MODULE_node_module__ from "node:module";
|
|
10
10
|
import * as __WEBPACK_EXTERNAL_MODULE_module__ from "module";
|
|
11
|
-
|
|
12
|
-
* Node.js built-in modules.
|
|
13
|
-
* Copied from https://github.com/webpack/webpack/blob/dd44b206a9c50f4b4cb4d134e1a0bd0387b159a3/lib/node/NodeTargetPlugin.js#L12-L72
|
|
14
|
-
*/ const nodeBuiltInModules = [
|
|
11
|
+
const nodeBuiltInModules = [
|
|
15
12
|
'assert',
|
|
16
13
|
'assert/strict',
|
|
17
14
|
'async_hooks',
|
|
@@ -67,15 +64,10 @@ import * as __WEBPACK_EXTERNAL_MODULE_module__ from "module";
|
|
|
67
64
|
'worker_threads',
|
|
68
65
|
'zlib',
|
|
69
66
|
/^node:/,
|
|
70
|
-
// cspell:word pnpapi
|
|
71
|
-
// Yarn PnP adds pnpapi as "builtin"
|
|
72
67
|
'pnpapi'
|
|
73
68
|
];
|
|
74
69
|
async function calcLongestCommonPath(absPaths) {
|
|
75
70
|
if (0 === absPaths.length) return null;
|
|
76
|
-
// we support two cases
|
|
77
|
-
// 1. /packages-a/src/index.ts
|
|
78
|
-
// 2. D:/packages-a/src/index.ts
|
|
79
71
|
const sep = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep;
|
|
80
72
|
const splitPaths = absPaths.map((p)=>p.split(sep));
|
|
81
73
|
let lcaFragments = splitPaths[0];
|
|
@@ -128,10 +120,12 @@ function isPluginIncluded(pluginName, plugins) {
|
|
|
128
120
|
return false;
|
|
129
121
|
}));
|
|
130
122
|
}
|
|
131
|
-
function checkMFPlugin(config) {
|
|
123
|
+
function checkMFPlugin(config, sharedPlugins) {
|
|
132
124
|
if ('mf' !== config.format) return true;
|
|
133
|
-
|
|
134
|
-
|
|
125
|
+
const added = isPluginIncluded('rsbuild:module-federation-enhanced', [
|
|
126
|
+
...sharedPlugins || [],
|
|
127
|
+
...config.plugins || []
|
|
128
|
+
]);
|
|
135
129
|
if (!added) {
|
|
136
130
|
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn(`${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].green('format: "mf"')} should be used with ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].blue('@module-federation/rsbuild-plugin')}", consider installing and adding it to plugins. Check the documentation (https://module-federation.io/guide/basic/rsbuild.html#rslib-module) to get started with "mf" output.`);
|
|
137
131
|
process.exit(1);
|
|
@@ -147,10 +141,12 @@ function debounce(func, wait) {
|
|
|
147
141
|
}, wait);
|
|
148
142
|
};
|
|
149
143
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
144
|
+
const isTTY = (type = 'stdout')=>('stdin' === type ? process.stdin.isTTY : process.stdout.isTTY) && !process.env.CI;
|
|
145
|
+
const isIntermediateOutputFormat = (format)=>'cjs' === format || 'esm' === format;
|
|
146
|
+
const windowsSlashRegex = /\\/g;
|
|
147
|
+
function normalizeSlash(p) {
|
|
148
|
+
return p.replace(windowsSlashRegex, '/');
|
|
149
|
+
}
|
|
154
150
|
if (process.env.DEBUG) __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.level = 'verbose';
|
|
155
151
|
function initNodeEnv() {
|
|
156
152
|
if (!process.env.NODE_ENV) {
|
|
@@ -162,12 +158,20 @@ function initNodeEnv() {
|
|
|
162
158
|
}
|
|
163
159
|
function prepareCli() {
|
|
164
160
|
initNodeEnv();
|
|
165
|
-
// Print a blank line to keep the greet log nice.
|
|
166
|
-
// Some package managers automatically output a blank line, some do not.
|
|
167
161
|
const { npm_execpath } = process.env;
|
|
168
162
|
if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
|
|
169
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rslib v0.1.
|
|
163
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rslib v0.1.5\n`);
|
|
170
164
|
}
|
|
165
|
+
const composeAssetConfig = (bundle, format)=>{
|
|
166
|
+
if ('esm' === format || 'cjs' === format) {
|
|
167
|
+
if (bundle) return {
|
|
168
|
+
output: {
|
|
169
|
+
dataUriLimit: 0
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
return {};
|
|
174
|
+
};
|
|
171
175
|
const DEFAULT_CONFIG_NAME = 'rslib.config';
|
|
172
176
|
const DEFAULT_CONFIG_EXTENSIONS = [
|
|
173
177
|
'.js',
|
|
@@ -234,10 +238,7 @@ function isCssFile(filepath) {
|
|
|
234
238
|
return CSS_EXTENSIONS_PATTERN.test(filepath);
|
|
235
239
|
}
|
|
236
240
|
const CSS_MODULE_REG = /\.module\.\w+$/i;
|
|
237
|
-
|
|
238
|
-
* This function is modified based on
|
|
239
|
-
* https://github.com/web-infra-dev/rspack/blob/7b80a45a1c58de7bc506dbb107fad6fda37d2a1f/packages/rspack/src/loader-runner/index.ts#L903
|
|
240
|
-
*/ const PATH_QUERY_FRAGMENT_REGEXP = /^((?:\u200b.|[^?#\u200b])*)(\?(?:\u200b.|[^#\u200b])*)?(#.*)?$/;
|
|
241
|
+
const PATH_QUERY_FRAGMENT_REGEXP = /^((?:\u200b.|[^?#\u200b])*)(\?(?:\u200b.|[^#\u200b])*)?(#.*)?$/;
|
|
241
242
|
function parsePathQueryFragment(str) {
|
|
242
243
|
const match = PATH_QUERY_FRAGMENT_REGEXP.exec(str);
|
|
243
244
|
return {
|
|
@@ -252,7 +253,6 @@ function isCssModulesFile(filepath, auto) {
|
|
|
252
253
|
if (auto instanceof RegExp) return auto.test(filepath);
|
|
253
254
|
if ('function' == typeof auto) {
|
|
254
255
|
const { path, query, fragment } = parsePathQueryFragment(filepath);
|
|
255
|
-
// this is a mock for loader
|
|
256
256
|
return auto(path, query, fragment);
|
|
257
257
|
}
|
|
258
258
|
return false;
|
|
@@ -265,16 +265,11 @@ function isCssGlobalFile(filepath, auto) {
|
|
|
265
265
|
}
|
|
266
266
|
function cssExternalHandler(request, callback, jsExtension, auto, isStyleRedirect) {
|
|
267
267
|
const isCssModulesRequest = isCssModulesFile(request, auto);
|
|
268
|
-
// cssExtract would execute the file handled by css-loader, so we cannot external the "helper import" from css-loader
|
|
269
|
-
// do not external @rsbuild/core/compiled/css-loader/noSourceMaps.js, sourceMaps.js, api.mjs etc.
|
|
270
268
|
if (/compiled\/css-loader\//.test(request)) return callback();
|
|
271
|
-
// 1. css modules: import './CounterButton.module.scss' -> import './CounterButton.module.mjs'
|
|
272
|
-
// 2. css global: import './CounterButton.scss' -> import './CounterButton.css'
|
|
273
269
|
if ('.' === request[0] && isCssFile(request)) {
|
|
274
|
-
|
|
275
|
-
if (
|
|
276
|
-
|
|
277
|
-
return callback(null, request.replace(/\.[^.]+$/, '.css'));
|
|
270
|
+
if (!isStyleRedirect) return callback(void 0, request);
|
|
271
|
+
if (isCssModulesRequest) return callback(void 0, request.replace(/\.[^.]+$/, jsExtension));
|
|
272
|
+
return callback(void 0, request.replace(/\.[^.]+$/, '.css'));
|
|
278
273
|
}
|
|
279
274
|
return false;
|
|
280
275
|
}
|
|
@@ -318,14 +313,11 @@ const composeCssConfig = (rootDir, bundle = true)=>{
|
|
|
318
313
|
],
|
|
319
314
|
tools: {
|
|
320
315
|
cssLoader: {
|
|
321
|
-
// Otherwise, external variables will be executed by css-extract and cause an error.
|
|
322
|
-
// e.g: `@import url('./a.css');`
|
|
323
316
|
import: false
|
|
324
317
|
}
|
|
325
318
|
}
|
|
326
319
|
};
|
|
327
320
|
};
|
|
328
|
-
// The shim will be injected in PostEntryPlugin.
|
|
329
321
|
const importMetaUrlShim = `const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
330
322
|
return typeof document === 'undefined'
|
|
331
323
|
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
@@ -333,10 +325,6 @@ const importMetaUrlShim = `const __rslib_import_meta_url__ = /*#__PURE__*/ (func
|
|
|
333
325
|
new URL('main.js', document.baseURI).href;
|
|
334
326
|
})();
|
|
335
327
|
`;
|
|
336
|
-
// This Rsbuild plugin will shim `import.meta.url` for CommonJS modules.
|
|
337
|
-
// - Replace `import.meta.url` with `importMetaUrl`.
|
|
338
|
-
// - Inject `importMetaUrl` to the end of the module (can't inject at the beginning because of `"use strict";`).
|
|
339
|
-
// This is a short-term solution, and we hope to provide built-in polyfills like `node.__filename` on Rspack side.
|
|
340
328
|
const pluginCjsImportMetaUrlShim = ()=>({
|
|
341
329
|
name: 'rsbuild:cjs-import-meta-url-shim',
|
|
342
330
|
setup (api) {
|
|
@@ -359,7 +347,6 @@ const pluginEsmRequireShim = ()=>({
|
|
|
359
347
|
config.plugins ??= [];
|
|
360
348
|
config.plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.BannerPlugin({
|
|
361
349
|
banner: requireShim,
|
|
362
|
-
// Just before minify stage, to perform tree shaking.
|
|
363
350
|
stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE - 1,
|
|
364
351
|
raw: true,
|
|
365
352
|
include: /\.(js|cjs)$/
|
|
@@ -402,12 +389,10 @@ class EntryChunkPlugin {
|
|
|
402
389
|
const content = compiler.inputFileSystem.readFileSync(filename, {
|
|
403
390
|
encoding: 'utf-8'
|
|
404
391
|
});
|
|
405
|
-
// Shebang
|
|
406
392
|
if (content.startsWith(SHEBANG_PREFIX)) {
|
|
407
393
|
const shebangMatch = matchFirstLine(content, SHEBANG_REGEX);
|
|
408
394
|
if (shebangMatch) this.shebangEntries[name] = shebangMatch;
|
|
409
395
|
}
|
|
410
|
-
// React directive
|
|
411
396
|
const reactDirective = matchFirstLine(content, REACT_DIRECTIVE_REGEX);
|
|
412
397
|
if (reactDirective) this.reactDirectives[name] = reactDirective;
|
|
413
398
|
}
|
|
@@ -438,7 +423,6 @@ class EntryChunkPlugin {
|
|
|
438
423
|
});
|
|
439
424
|
compilation.hooks.processAssets.tap({
|
|
440
425
|
name: EntryChunkPlugin_PLUGIN_NAME,
|
|
441
|
-
// Just after minify stage, to avoid from being minified.
|
|
442
426
|
stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_DEV_TOOLING - 1
|
|
443
427
|
}, (assets)=>{
|
|
444
428
|
const chunkAsset = Object.keys(assets);
|
|
@@ -447,12 +431,10 @@ class EntryChunkPlugin {
|
|
|
447
431
|
const reactDirectiveValue = this.reactDirectives[name];
|
|
448
432
|
if (shebangValue || reactDirectiveValue) compilation.updateAsset(name, (old)=>{
|
|
449
433
|
const replaceSource = new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.sources.ReplaceSource(old);
|
|
450
|
-
// Shebang
|
|
451
434
|
if (shebangValue) {
|
|
452
435
|
replaceSource.insert(0, `${shebangValue}\n`);
|
|
453
436
|
this.shebangInjectedAssets.add(name);
|
|
454
437
|
}
|
|
455
|
-
// React directives
|
|
456
438
|
if (reactDirectiveValue) replaceSource.insert(0, `${reactDirectiveValue}\n`);
|
|
457
439
|
return replaceSource;
|
|
458
440
|
});
|
|
@@ -541,13 +523,7 @@ const RSPACK_TARGET_UNLISTED_MODERN_ECMA_VERSIONS = [
|
|
|
541
523
|
'es2024',
|
|
542
524
|
'esnext'
|
|
543
525
|
];
|
|
544
|
-
|
|
545
|
-
* The esX to browserslist mapping is transformed from esbuild:
|
|
546
|
-
* https://github.com/evanw/esbuild/blob/main/internal/compat/js_table.go
|
|
547
|
-
* It does not completely align with the browserslist query of Rsbuild now:
|
|
548
|
-
* https://github.com/rspack-contrib/browserslist-to-es-version
|
|
549
|
-
* TODO: align with Rsbuild, we may should align with SWC
|
|
550
|
-
*/ const ESX_TO_BROWSERSLIST = {
|
|
526
|
+
const ESX_TO_BROWSERSLIST = {
|
|
551
527
|
es5: {
|
|
552
528
|
chrome: '5.0.0',
|
|
553
529
|
edge: '12.0.0',
|
|
@@ -652,10 +628,7 @@ function transformSyntaxToRspackTarget(syntax) {
|
|
|
652
628
|
const normalizedSyntaxItem = syntaxItem.toLowerCase();
|
|
653
629
|
if (normalizedSyntaxItem.startsWith('es')) {
|
|
654
630
|
if (normalizedSyntaxItem in ESX_TO_BROWSERSLIST) {
|
|
655
|
-
// The latest EcmaScript version supported by Rspack's `target` is es2022.
|
|
656
|
-
// Higher versions are treated as es2022.
|
|
657
631
|
if (RSPACK_TARGET_UNLISTED_MODERN_ECMA_VERSIONS.includes(normalizedSyntaxItem)) return 'es2022';
|
|
658
|
-
// The es6 is the same as es2015, compatible with rspack API schema
|
|
659
632
|
if ('es6' === normalizedSyntaxItem) return 'es2015';
|
|
660
633
|
return normalizedSyntaxItem;
|
|
661
634
|
}
|
|
@@ -691,7 +664,7 @@ function transformSyntaxToBrowserslist(syntax, target) {
|
|
|
691
664
|
}
|
|
692
665
|
const POSIX_SEP_RE = new RegExp('\\' + __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep, 'g');
|
|
693
666
|
const NATIVE_SEP_RE = new RegExp('\\' + __WEBPACK_EXTERNAL_MODULE_node_path__["default"].sep, 'g');
|
|
694
|
-
|
|
667
|
+
const PATTERN_REGEX_CACHE = new Map();
|
|
695
668
|
const GLOB_ALL_PATTERN = "**/*";
|
|
696
669
|
const TS_EXTENSIONS = [
|
|
697
670
|
'.ts',
|
|
@@ -709,10 +682,7 @@ const TSJS_EXTENSIONS = TS_EXTENSIONS.concat(util_JS_EXTENSIONS);
|
|
|
709
682
|
const TS_EXTENSIONS_RE_GROUP = `\\.(?:${TS_EXTENSIONS.map((ext)=>ext.substring(1)).join('|')})`;
|
|
710
683
|
const TSJS_EXTENSIONS_RE_GROUP = `\\.(?:${TSJS_EXTENSIONS.map((ext)=>ext.substring(1)).join('|')})`;
|
|
711
684
|
const IS_POSIX = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep === __WEBPACK_EXTERNAL_MODULE_node_path__["default"].sep;
|
|
712
|
-
|
|
713
|
-
* @template T
|
|
714
|
-
* @returns {{resolve:(result:T)=>void, reject:(error:any)=>void, promise: Promise<T>}}
|
|
715
|
-
*/ function util_makePromise() {
|
|
685
|
+
function util_makePromise() {
|
|
716
686
|
let resolve, reject;
|
|
717
687
|
const promise = new Promise((res, rej)=>{
|
|
718
688
|
resolve = res;
|
|
@@ -724,12 +694,8 @@ const IS_POSIX = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep ===
|
|
|
724
694
|
reject
|
|
725
695
|
};
|
|
726
696
|
}
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
* @param {import('./cache.js').TSConfckCache} [cache]
|
|
730
|
-
* @returns {Promise<string|void>}
|
|
731
|
-
*/ async function util_resolveTSConfigJson(filename, cache) {
|
|
732
|
-
if ('.json' !== __WEBPACK_EXTERNAL_MODULE_node_path__["default"].extname(filename)) return; // ignore files that are not json
|
|
697
|
+
async function util_resolveTSConfigJson(filename, cache) {
|
|
698
|
+
if ('.json' !== __WEBPACK_EXTERNAL_MODULE_node_path__["default"].extname(filename)) return;
|
|
733
699
|
const tsconfig = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(filename);
|
|
734
700
|
if (cache && (cache.hasParseResult(tsconfig) || cache.hasParseResult(filename))) return tsconfig;
|
|
735
701
|
return __WEBPACK_EXTERNAL_MODULE_node_fs__.promises.stat(tsconfig).then((stat)=>{
|
|
@@ -737,57 +703,18 @@ const IS_POSIX = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep ===
|
|
|
737
703
|
throw new Error(`${filename} exists but is not a regular file.`);
|
|
738
704
|
});
|
|
739
705
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
/**
|
|
746
|
-
* convert posix separator to native separator
|
|
747
|
-
*
|
|
748
|
-
* eg.
|
|
749
|
-
* windows: C:/foo/bar -> c:\foo\bar
|
|
750
|
-
* linux: /foo/bar -> /foo/bar
|
|
751
|
-
*
|
|
752
|
-
* @param {string} filename with posix separators
|
|
753
|
-
* @returns {string} filename with native separators
|
|
754
|
-
*/ const posix2native = IS_POSIX ? (filename)=>filename : (filename)=>filename.replace(POSIX_SEP_RE, __WEBPACK_EXTERNAL_MODULE_node_path__["default"].sep);
|
|
755
|
-
/**
|
|
756
|
-
* convert native separator to posix separator
|
|
757
|
-
*
|
|
758
|
-
* eg.
|
|
759
|
-
* windows: C:\foo\bar -> c:/foo/bar
|
|
760
|
-
* linux: /foo/bar -> /foo/bar
|
|
761
|
-
*
|
|
762
|
-
* @param {string} filename - filename with native separators
|
|
763
|
-
* @returns {string} filename with posix separators
|
|
764
|
-
*/ const util_native2posix = IS_POSIX ? (filename)=>filename : (filename)=>filename.replace(NATIVE_SEP_RE, __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep);
|
|
765
|
-
/**
|
|
766
|
-
* converts params to native separator, resolves path and converts native back to posix
|
|
767
|
-
*
|
|
768
|
-
* needed on windows to handle posix paths in tsconfig
|
|
769
|
-
*
|
|
770
|
-
* @param dir {string|null} directory to resolve from
|
|
771
|
-
* @param filename {string} filename or pattern to resolve
|
|
772
|
-
* @returns string
|
|
773
|
-
*/ const resolve2posix = IS_POSIX ? (dir, filename)=>dir ? __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(dir, filename) : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(filename) : (dir, filename)=>util_native2posix(dir ? __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(posix2native(dir), posix2native(filename)) : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(posix2native(filename)));
|
|
774
|
-
/**
|
|
775
|
-
*
|
|
776
|
-
* @param {import('./public.d.ts').TSConfckParseResult} result
|
|
777
|
-
* @param {import('./public.d.ts').TSConfckParseOptions} [options]
|
|
778
|
-
* @returns {string[]}
|
|
779
|
-
*/ function util_resolveReferencedTSConfigFiles(result, options) {
|
|
706
|
+
const util_isInNodeModules = IS_POSIX ? (dir)=>dir.includes('/node_modules/') : (dir)=>dir.match(/[/\\]node_modules[/\\]/);
|
|
707
|
+
const posix2native = IS_POSIX ? (filename)=>filename : (filename)=>filename.replace(POSIX_SEP_RE, __WEBPACK_EXTERNAL_MODULE_node_path__["default"].sep);
|
|
708
|
+
const util_native2posix = IS_POSIX ? (filename)=>filename : (filename)=>filename.replace(NATIVE_SEP_RE, __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep);
|
|
709
|
+
const resolve2posix = IS_POSIX ? (dir, filename)=>dir ? __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(dir, filename) : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(filename) : (dir, filename)=>util_native2posix(dir ? __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(posix2native(dir), posix2native(filename)) : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(posix2native(filename)));
|
|
710
|
+
function util_resolveReferencedTSConfigFiles(result, options) {
|
|
780
711
|
const dir = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(result.tsconfigFile);
|
|
781
712
|
return result.tsconfig.references.map((ref)=>{
|
|
782
713
|
const refPath = ref.path.endsWith('.json') ? ref.path : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(ref.path, options?.configName ?? 'tsconfig.json');
|
|
783
714
|
return resolve2posix(dir, refPath);
|
|
784
715
|
});
|
|
785
716
|
}
|
|
786
|
-
|
|
787
|
-
* @param {string} filename
|
|
788
|
-
* @param {import('./public.d.ts').TSConfckParseResult} result
|
|
789
|
-
* @returns {import('./public.d.ts').TSConfckParseResult}
|
|
790
|
-
*/ function util_resolveSolutionTSConfig(filename, result) {
|
|
717
|
+
function util_resolveSolutionTSConfig(filename, result) {
|
|
791
718
|
const allowJs = result.tsconfig.compilerOptions?.allowJs;
|
|
792
719
|
const extensions = allowJs ? TSJS_EXTENSIONS : TS_EXTENSIONS;
|
|
793
720
|
if (result.referenced && extensions.some((ext)=>filename.endsWith(ext)) && !util_isIncluded(filename, result)) {
|
|
@@ -796,12 +723,7 @@ const IS_POSIX = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep ===
|
|
|
796
723
|
}
|
|
797
724
|
return result;
|
|
798
725
|
}
|
|
799
|
-
|
|
800
|
-
*
|
|
801
|
-
* @param {string} filename
|
|
802
|
-
* @param {import('./public.d.ts').TSConfckParseResult} result
|
|
803
|
-
* @returns {boolean}
|
|
804
|
-
*/ function util_isIncluded(filename, result) {
|
|
726
|
+
function util_isIncluded(filename, result) {
|
|
805
727
|
const dir = util_native2posix(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(result.tsconfigFile));
|
|
806
728
|
const files = (result.tsconfig.files || []).map((file)=>resolve2posix(dir, file));
|
|
807
729
|
const absoluteFilename = resolve2posix(null, filename);
|
|
@@ -816,18 +738,9 @@ const IS_POSIX = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep ===
|
|
|
816
738
|
}
|
|
817
739
|
return false;
|
|
818
740
|
}
|
|
819
|
-
|
|
820
|
-
* test filenames agains glob patterns in tsconfig
|
|
821
|
-
*
|
|
822
|
-
* @param filename {string} posix style abolute path to filename to test
|
|
823
|
-
* @param dir {string} posix style absolute path to directory of tsconfig containing patterns
|
|
824
|
-
* @param patterns {string[]} glob patterns to match against
|
|
825
|
-
* @param allowJs {boolean} allowJs setting in tsconfig to include js extensions in checks
|
|
826
|
-
* @returns {boolean} true when at least one pattern matches filename
|
|
827
|
-
*/ function isGlobMatch(filename, dir, patterns, allowJs) {
|
|
741
|
+
function isGlobMatch(filename, dir, patterns, allowJs) {
|
|
828
742
|
const extensions = allowJs ? TSJS_EXTENSIONS : TS_EXTENSIONS;
|
|
829
743
|
return patterns.some((pattern)=>{
|
|
830
|
-
// filename must end with part of pattern that comes after last wildcard
|
|
831
744
|
let lastWildcardIndex = pattern.length;
|
|
832
745
|
let hasWildcard = false;
|
|
833
746
|
let hasExtension = false;
|
|
@@ -851,19 +764,14 @@ const IS_POSIX = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep ===
|
|
|
851
764
|
if (hasWildcard && hasSlash) break;
|
|
852
765
|
}
|
|
853
766
|
if (!hasExtension && (!hasWildcard || lastWildcardIndex < lastSlashIndex)) {
|
|
854
|
-
// add implicit glob
|
|
855
767
|
pattern += `${pattern.endsWith('/') ? '' : '/'}${GLOB_ALL_PATTERN}`;
|
|
856
768
|
lastWildcardIndex = pattern.length - 1;
|
|
857
769
|
hasWildcard = true;
|
|
858
770
|
}
|
|
859
|
-
// if pattern does not end with wildcard, filename must end with pattern after last wildcard
|
|
860
771
|
if (lastWildcardIndex < pattern.length - 1 && !filename.endsWith(pattern.slice(lastWildcardIndex + 1))) return false;
|
|
861
|
-
// if pattern ends with *, filename must end with a default extension
|
|
862
772
|
if (pattern.endsWith('*') && !extensions.some((ext)=>filename.endsWith(ext))) return false;
|
|
863
|
-
// for **/* , filename must start with the dir
|
|
864
773
|
if (pattern === GLOB_ALL_PATTERN) return filename.startsWith(`${dir}/`);
|
|
865
774
|
const resolvedPattern = resolve2posix(dir, pattern);
|
|
866
|
-
// filename must start with part of pattern that comes before first wildcard
|
|
867
775
|
let firstWildcardIndex = -1;
|
|
868
776
|
for(let i = 0; i < resolvedPattern.length; i++)if ('*' === resolvedPattern[i] || '?' === resolvedPattern[i]) {
|
|
869
777
|
firstWildcardIndex = i;
|
|
@@ -871,22 +779,15 @@ const IS_POSIX = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep ===
|
|
|
871
779
|
break;
|
|
872
780
|
}
|
|
873
781
|
if (firstWildcardIndex > 1 && !filename.startsWith(resolvedPattern.slice(0, firstWildcardIndex - 1))) return false;
|
|
874
|
-
if (!hasWildcard)
|
|
875
|
-
|
|
876
|
-
if (firstWildcardIndex + GLOB_ALL_PATTERN.length === resolvedPattern.length - (pattern.length - 1 - lastWildcardIndex) && resolvedPattern.slice(firstWildcardIndex, firstWildcardIndex + GLOB_ALL_PATTERN.length) === GLOB_ALL_PATTERN) // singular glob-all pattern and we already validated prefix and suffix matches
|
|
877
|
-
return true;
|
|
878
|
-
// complex pattern, use regex to check it
|
|
782
|
+
if (!hasWildcard) return filename === resolvedPattern;
|
|
783
|
+
if (firstWildcardIndex + GLOB_ALL_PATTERN.length === resolvedPattern.length - (pattern.length - 1 - lastWildcardIndex) && resolvedPattern.slice(firstWildcardIndex, firstWildcardIndex + GLOB_ALL_PATTERN.length) === GLOB_ALL_PATTERN) return true;
|
|
879
784
|
if (PATTERN_REGEX_CACHE.has(resolvedPattern)) return PATTERN_REGEX_CACHE.get(resolvedPattern).test(filename);
|
|
880
785
|
const regex = pattern2regex(resolvedPattern, allowJs);
|
|
881
786
|
PATTERN_REGEX_CACHE.set(resolvedPattern, regex);
|
|
882
787
|
return regex.test(filename);
|
|
883
788
|
});
|
|
884
789
|
}
|
|
885
|
-
|
|
886
|
-
* @param {string} resolvedPattern
|
|
887
|
-
* @param {boolean} allowJs
|
|
888
|
-
* @returns {RegExp}
|
|
889
|
-
*/ function pattern2regex(resolvedPattern, allowJs) {
|
|
790
|
+
function pattern2regex(resolvedPattern, allowJs) {
|
|
890
791
|
let regexStr = '^';
|
|
891
792
|
for(let i = 0; i < resolvedPattern.length; i++){
|
|
892
793
|
const char = resolvedPattern[i];
|
|
@@ -897,7 +798,7 @@ const IS_POSIX = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep ===
|
|
|
897
798
|
if ('*' === char) {
|
|
898
799
|
if ('*' === resolvedPattern[i + 1] && '/' === resolvedPattern[i + 2]) {
|
|
899
800
|
i += 2;
|
|
900
|
-
regexStr += '(?:[^\\/]*\\/)*';
|
|
801
|
+
regexStr += '(?:[^\\/]*\\/)*';
|
|
901
802
|
continue;
|
|
902
803
|
}
|
|
903
804
|
regexStr += '[^\\/]*';
|
|
@@ -906,27 +807,14 @@ const IS_POSIX = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep ===
|
|
|
906
807
|
if ('/.+^${}()|[]\\'.includes(char)) regexStr += "\\";
|
|
907
808
|
regexStr += char;
|
|
908
809
|
}
|
|
909
|
-
// add known file endings if pattern ends on *
|
|
910
810
|
if (resolvedPattern.endsWith('*')) regexStr += allowJs ? TSJS_EXTENSIONS_RE_GROUP : TS_EXTENSIONS_RE_GROUP;
|
|
911
811
|
regexStr += '$';
|
|
912
812
|
return new RegExp(regexStr);
|
|
913
813
|
}
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
* @returns {any}
|
|
919
|
-
*/ function util_replaceTokens(tsconfig, configDir) {
|
|
920
|
-
return JSON.parse(JSON.stringify(tsconfig)// replace ${configDir}
|
|
921
|
-
.replaceAll(/"\${configDir}/g, `"${util_native2posix(configDir)}`));
|
|
922
|
-
}
|
|
923
|
-
/**
|
|
924
|
-
* find the closest tsconfig.json file
|
|
925
|
-
*
|
|
926
|
-
* @param {string} filename - path to file to find tsconfig for (absolute or relative to cwd)
|
|
927
|
-
* @param {import('./public.d.ts').TSConfckFindOptions} [options] - options
|
|
928
|
-
* @returns {Promise<string|null>} absolute path to closest tsconfig.json or null if not found
|
|
929
|
-
*/ async function find(filename, options) {
|
|
814
|
+
function util_replaceTokens(tsconfig, configDir) {
|
|
815
|
+
return JSON.parse(JSON.stringify(tsconfig).replaceAll(/"\${configDir}/g, `"${util_native2posix(configDir)}`));
|
|
816
|
+
}
|
|
817
|
+
async function find(filename, options) {
|
|
930
818
|
let dir = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(filename));
|
|
931
819
|
if (options?.ignoreNodeModules && util_isInNodeModules(dir)) return null;
|
|
932
820
|
const cache = options?.cache;
|
|
@@ -941,12 +829,7 @@ const IS_POSIX = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep ===
|
|
|
941
829
|
}, options);
|
|
942
830
|
return promise;
|
|
943
831
|
}
|
|
944
|
-
|
|
945
|
-
*
|
|
946
|
-
* @param {string} dir
|
|
947
|
-
* @param {{promise:Promise<string|null>,resolve:(result:string|null)=>void,reject:(err:any)=>void}} madePromise
|
|
948
|
-
* @param {import('./public.d.ts').TSConfckFindOptions} [options] - options
|
|
949
|
-
*/ function findUp(dir, { resolve, reject, promise }, options) {
|
|
832
|
+
function findUp(dir, { resolve, reject, promise }, options) {
|
|
950
833
|
const { cache, root, configName } = options ?? {};
|
|
951
834
|
if (cache) {
|
|
952
835
|
if (cache.hasConfigPath(dir, configName)) {
|
|
@@ -976,38 +859,13 @@ const IS_POSIX = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep ===
|
|
|
976
859
|
}
|
|
977
860
|
});
|
|
978
861
|
}
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
* @interface
|
|
982
|
-
* @property {string[]} files - files
|
|
983
|
-
* @property {number} calls - number of ongoing calls
|
|
984
|
-
* @property {(dir: string)=>boolean} skip - function to skip dirs
|
|
985
|
-
* @property {boolean} err - error flag
|
|
986
|
-
* @property {string[]} configNames - config file names
|
|
987
|
-
*/ __WEBPACK_EXTERNAL_MODULE_node_path__["default"].sep;
|
|
988
|
-
/*
|
|
989
|
-
this file contains code from strip-bom and strip-json-comments by Sindre Sorhus
|
|
990
|
-
https://github.com/sindresorhus/strip-json-comments/blob/v4.0.0/index.js
|
|
991
|
-
https://github.com/sindresorhus/strip-bom/blob/v5.0.0/index.js
|
|
992
|
-
licensed under MIT, see ../LICENSE
|
|
993
|
-
*/ /**
|
|
994
|
-
* convert content of tsconfig.json to regular json
|
|
995
|
-
*
|
|
996
|
-
* @param {string} tsconfigJson - content of tsconfig.json
|
|
997
|
-
* @returns {string} content as regular json, comments and dangling commas have been replaced with whitespace
|
|
998
|
-
*/ function toJson(tsconfigJson) {
|
|
862
|
+
__WEBPACK_EXTERNAL_MODULE_node_path__["default"].sep;
|
|
863
|
+
function toJson(tsconfigJson) {
|
|
999
864
|
const stripped = stripDanglingComma(stripJsonComments(stripBom(tsconfigJson)));
|
|
1000
|
-
if ('' === stripped.trim())
|
|
1001
|
-
return '{}';
|
|
865
|
+
if ('' === stripped.trim()) return '{}';
|
|
1002
866
|
return stripped;
|
|
1003
867
|
}
|
|
1004
|
-
|
|
1005
|
-
* replace dangling commas from pseudo-json string with single space
|
|
1006
|
-
* implementation heavily inspired by strip-json-comments
|
|
1007
|
-
*
|
|
1008
|
-
* @param {string} pseudoJson
|
|
1009
|
-
* @returns {string}
|
|
1010
|
-
*/ function stripDanglingComma(pseudoJson) {
|
|
868
|
+
function stripDanglingComma(pseudoJson) {
|
|
1011
869
|
let insideString = false;
|
|
1012
870
|
let offset = 0;
|
|
1013
871
|
let result = '';
|
|
@@ -1036,13 +894,7 @@ const IS_POSIX = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep ===
|
|
|
1036
894
|
}
|
|
1037
895
|
return result + pseudoJson.substring(offset);
|
|
1038
896
|
}
|
|
1039
|
-
|
|
1040
|
-
/**
|
|
1041
|
-
*
|
|
1042
|
-
* @param {string} jsonString
|
|
1043
|
-
* @param {number} quotePosition
|
|
1044
|
-
* @returns {boolean}
|
|
1045
|
-
*/ function isEscaped(jsonString, quotePosition) {
|
|
897
|
+
function isEscaped(jsonString, quotePosition) {
|
|
1046
898
|
let index = quotePosition - 1;
|
|
1047
899
|
let backslashCount = 0;
|
|
1048
900
|
while('\\' === jsonString[index]){
|
|
@@ -1051,22 +903,14 @@ const IS_POSIX = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep ===
|
|
|
1051
903
|
}
|
|
1052
904
|
return Boolean(backslashCount % 2);
|
|
1053
905
|
}
|
|
1054
|
-
|
|
1055
|
-
*
|
|
1056
|
-
* @param {string} string
|
|
1057
|
-
* @param {number?} start
|
|
1058
|
-
* @param {number?} end
|
|
1059
|
-
*/ function strip(string, start, end) {
|
|
906
|
+
function strip(string, start, end) {
|
|
1060
907
|
return string.slice(start, end).replace(/\S/g, ' ');
|
|
1061
908
|
}
|
|
1062
909
|
const singleComment = Symbol('singleComment');
|
|
1063
910
|
const multiComment = Symbol('multiComment');
|
|
1064
|
-
|
|
1065
|
-
* @param {string} jsonString
|
|
1066
|
-
* @returns {string}
|
|
1067
|
-
*/ function stripJsonComments(jsonString) {
|
|
911
|
+
function stripJsonComments(jsonString) {
|
|
1068
912
|
let isInsideString = false;
|
|
1069
|
-
|
|
913
|
+
let isInsideComment = false;
|
|
1070
914
|
let offset = 0;
|
|
1071
915
|
let result = '';
|
|
1072
916
|
for(let index = 0; index < jsonString.length; index++){
|
|
@@ -1108,14 +952,7 @@ const multiComment = Symbol('multiComment');
|
|
|
1108
952
|
}
|
|
1109
953
|
return result + (isInsideComment ? strip(jsonString.slice(offset)) : jsonString.slice(offset));
|
|
1110
954
|
}
|
|
1111
|
-
|
|
1112
|
-
// start strip-bom
|
|
1113
|
-
/**
|
|
1114
|
-
* @param {string} string
|
|
1115
|
-
* @returns {string}
|
|
1116
|
-
*/ function stripBom(string) {
|
|
1117
|
-
// Catches EFBBBF (UTF-8 BOM) because the buffer-to-string
|
|
1118
|
-
// conversion translates it to FEFF (UTF-16 BOM).
|
|
955
|
+
function stripBom(string) {
|
|
1119
956
|
if (0xfeff === string.charCodeAt(0)) return string.slice(1);
|
|
1120
957
|
return string;
|
|
1121
958
|
}
|
|
@@ -1123,17 +960,10 @@ const not_found_result = {
|
|
|
1123
960
|
tsconfigFile: null,
|
|
1124
961
|
tsconfig: {}
|
|
1125
962
|
};
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
*
|
|
1129
|
-
* @param {string} filename - path to a tsconfig .json or a source file or directory (absolute or relative to cwd)
|
|
1130
|
-
* @param {import('./public.d.ts').TSConfckParseOptions} [options] - options
|
|
1131
|
-
* @returns {Promise<import('./public.d.ts').TSConfckParseResult>}
|
|
1132
|
-
* @throws {TSConfckParseError}
|
|
1133
|
-
*/ async function parse(filename, options) {
|
|
1134
|
-
/** @type {import('./cache.js').TSConfckCache} */ const cache = options?.cache;
|
|
963
|
+
async function parse(filename, options) {
|
|
964
|
+
const cache = options?.cache;
|
|
1135
965
|
if (cache?.hasParseResult(filename)) return getParsedDeep(filename, cache, options);
|
|
1136
|
-
const { resolve, reject,
|
|
966
|
+
const { resolve, reject, promise } = util_makePromise();
|
|
1137
967
|
cache?.setParseResult(filename, promise, true);
|
|
1138
968
|
try {
|
|
1139
969
|
let tsconfigFile = await util_resolveTSConfigJson(filename, cache) || await find(filename, options);
|
|
@@ -1157,13 +987,7 @@ const not_found_result = {
|
|
|
1157
987
|
}
|
|
1158
988
|
return promise;
|
|
1159
989
|
}
|
|
1160
|
-
|
|
1161
|
-
* ensure extends and references are parsed
|
|
1162
|
-
*
|
|
1163
|
-
* @param {string} filename - cached file
|
|
1164
|
-
* @param {import('./cache.js').TSConfckCache} cache - cache
|
|
1165
|
-
* @param {import('./public.d.ts').TSConfckParseOptions} options - options
|
|
1166
|
-
*/ async function getParsedDeep(filename, cache, options) {
|
|
990
|
+
async function getParsedDeep(filename, cache, options) {
|
|
1167
991
|
const result = await cache.getParseResult(filename);
|
|
1168
992
|
if (result.tsconfig.extends && !result.extended || result.tsconfig.references && !result.referenced) {
|
|
1169
993
|
const promise = Promise.all([
|
|
@@ -1175,13 +999,7 @@ const not_found_result = {
|
|
|
1175
999
|
}
|
|
1176
1000
|
return result;
|
|
1177
1001
|
}
|
|
1178
|
-
|
|
1179
|
-
*
|
|
1180
|
-
* @param {string} tsconfigFile - path to tsconfig file
|
|
1181
|
-
* @param {import('./cache.js').TSConfckCache} [cache] - cache
|
|
1182
|
-
* @param {boolean} [skipCache] - skip cache
|
|
1183
|
-
* @returns {Promise<import('./public.d.ts').TSConfckParseResult>}
|
|
1184
|
-
*/ async function parseFile(tsconfigFile, cache, skipCache) {
|
|
1002
|
+
async function parseFile(tsconfigFile, cache, skipCache) {
|
|
1185
1003
|
if (!skipCache && cache?.hasParseResult(tsconfigFile) && !cache.getParseResult(tsconfigFile)._isRootFile_) return cache.getParseResult(tsconfigFile);
|
|
1186
1004
|
const promise = __WEBPACK_EXTERNAL_MODULE_node_fs__.promises.readFile(tsconfigFile, 'utf-8').then(toJson).then((json)=>{
|
|
1187
1005
|
const parsed = JSON.parse(json);
|
|
@@ -1196,23 +1014,12 @@ const not_found_result = {
|
|
|
1196
1014
|
if (!skipCache && (!cache?.hasParseResult(tsconfigFile) || !cache.getParseResult(tsconfigFile)._isRootFile_)) cache?.setParseResult(tsconfigFile, promise);
|
|
1197
1015
|
return promise;
|
|
1198
1016
|
}
|
|
1199
|
-
|
|
1200
|
-
* normalize to match the output of ts.parseJsonConfigFileContent
|
|
1201
|
-
*
|
|
1202
|
-
* @param {any} tsconfig - typescript tsconfig output
|
|
1203
|
-
* @param {string} dir - directory
|
|
1204
|
-
*/ function normalizeTSConfig(tsconfig, dir) {
|
|
1205
|
-
// set baseUrl to absolute path
|
|
1017
|
+
function normalizeTSConfig(tsconfig, dir) {
|
|
1206
1018
|
const baseUrl = tsconfig.compilerOptions?.baseUrl;
|
|
1207
1019
|
if (baseUrl && !baseUrl.startsWith('${') && !__WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(baseUrl)) tsconfig.compilerOptions.baseUrl = resolve2posix(dir, baseUrl);
|
|
1208
1020
|
return tsconfig;
|
|
1209
1021
|
}
|
|
1210
|
-
|
|
1211
|
-
*
|
|
1212
|
-
* @param {import('./public.d.ts').TSConfckParseResult} result
|
|
1213
|
-
* @param {import('./public.d.ts').TSConfckParseOptions} [options]
|
|
1214
|
-
* @returns {Promise<void>}
|
|
1215
|
-
*/ async function parseReferences(result, options) {
|
|
1022
|
+
async function parseReferences(result, options) {
|
|
1216
1023
|
if (!result.tsconfig.references) return;
|
|
1217
1024
|
const referencedFiles = util_resolveReferencedTSConfigFiles(result, options);
|
|
1218
1025
|
const referenced = await Promise.all(referencedFiles.map((file)=>parseFile(file, options?.cache)));
|
|
@@ -1222,32 +1029,23 @@ const not_found_result = {
|
|
|
1222
1029
|
});
|
|
1223
1030
|
result.referenced = referenced;
|
|
1224
1031
|
}
|
|
1225
|
-
|
|
1226
|
-
* @param {import('./public.d.ts').TSConfckParseResult} result
|
|
1227
|
-
* @param {import('./cache.js').TSConfckCache}[cache]
|
|
1228
|
-
* @returns {Promise<void>}
|
|
1229
|
-
*/ async function parseExtends(result, cache) {
|
|
1032
|
+
async function parseExtends(result, cache) {
|
|
1230
1033
|
if (!result.tsconfig.extends) return;
|
|
1231
|
-
|
|
1232
|
-
// but dereference tsconfig so that mergeExtended can modify the original without affecting extended[0]
|
|
1233
|
-
/** @type {import('./public.d.ts').TSConfckParseResult[]} */ const extended = [
|
|
1034
|
+
const extended = [
|
|
1234
1035
|
{
|
|
1235
1036
|
tsconfigFile: result.tsconfigFile,
|
|
1236
1037
|
tsconfig: JSON.parse(JSON.stringify(result.tsconfig))
|
|
1237
1038
|
}
|
|
1238
1039
|
];
|
|
1239
|
-
// flatten extends graph into extended
|
|
1240
1040
|
let pos = 0;
|
|
1241
|
-
|
|
1041
|
+
const extendsPath = [];
|
|
1242
1042
|
let currentBranchDepth = 0;
|
|
1243
1043
|
while(pos < extended.length){
|
|
1244
1044
|
const extending = extended[pos];
|
|
1245
1045
|
extendsPath.push(extending.tsconfigFile);
|
|
1246
1046
|
if (extending.tsconfig.extends) {
|
|
1247
|
-
// keep following this branch
|
|
1248
1047
|
currentBranchDepth += 1;
|
|
1249
|
-
|
|
1250
|
-
// reverse because typescript 5.0 treats ['a','b','c'] as c extends b extends a
|
|
1048
|
+
let resolvedExtends;
|
|
1251
1049
|
resolvedExtends = Array.isArray(extending.tsconfig.extends) ? extending.tsconfig.extends.reverse().map((ex)=>resolveExtends(ex, extending.tsconfigFile)) : [
|
|
1252
1050
|
resolveExtends(extending.tsconfig.extends, extending.tsconfigFile)
|
|
1253
1051
|
];
|
|
@@ -1258,27 +1056,18 @@ const not_found_result = {
|
|
|
1258
1056
|
]).join(' -> ');
|
|
1259
1057
|
throw new TSConfckParseError(`Circular dependency in "extends": ${circle}`, 'EXTENDS_CIRCULAR', result.tsconfigFile);
|
|
1260
1058
|
}
|
|
1261
|
-
// add new extends to the list directly after current
|
|
1262
1059
|
extended.splice(pos + 1, 0, ...await Promise.all(resolvedExtends.map((file)=>parseFile(file, cache))));
|
|
1263
1060
|
} else {
|
|
1264
|
-
// reached a leaf, backtrack to the last branching point and continue
|
|
1265
1061
|
extendsPath.splice(-currentBranchDepth);
|
|
1266
1062
|
currentBranchDepth = 0;
|
|
1267
1063
|
}
|
|
1268
1064
|
pos += 1;
|
|
1269
1065
|
}
|
|
1270
1066
|
result.extended = extended;
|
|
1271
|
-
// skip first as it is the original config
|
|
1272
1067
|
for (const ext of result.extended.slice(1))extendTSConfig(result, ext);
|
|
1273
1068
|
}
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
* @param {string} extended
|
|
1277
|
-
* @param {string} from
|
|
1278
|
-
* @returns {string}
|
|
1279
|
-
*/ function resolveExtends(extended, from) {
|
|
1280
|
-
if ('..' === extended) // see #149
|
|
1281
|
-
extended = '../tsconfig.json';
|
|
1069
|
+
function resolveExtends(extended, from) {
|
|
1070
|
+
if ('..' === extended) extended = '../tsconfig.json';
|
|
1282
1071
|
const req = (0, __WEBPACK_EXTERNAL_MODULE_module__.createRequire)(from);
|
|
1283
1072
|
let error;
|
|
1284
1073
|
try {
|
|
@@ -1293,7 +1082,6 @@ const not_found_result = {
|
|
|
1293
1082
|
}
|
|
1294
1083
|
throw new TSConfckParseError(`failed to resolve "extends":"${extended}" in ${from}`, 'EXTENDS_RESOLVE', from, error);
|
|
1295
1084
|
}
|
|
1296
|
-
// references, extends and custom keys are not carried over
|
|
1297
1085
|
const EXTENDABLE_KEYS = [
|
|
1298
1086
|
'compilerOptions',
|
|
1299
1087
|
'files',
|
|
@@ -1304,12 +1092,7 @@ const EXTENDABLE_KEYS = [
|
|
|
1304
1092
|
'typeAcquisition',
|
|
1305
1093
|
'buildOptions'
|
|
1306
1094
|
];
|
|
1307
|
-
|
|
1308
|
-
*
|
|
1309
|
-
* @param {import('./public.d.ts').TSConfckParseResult} extending
|
|
1310
|
-
* @param {import('./public.d.ts').TSConfckParseResult} extended
|
|
1311
|
-
* @returns void
|
|
1312
|
-
*/ function extendTSConfig(extending, extended) {
|
|
1095
|
+
function extendTSConfig(extending, extended) {
|
|
1313
1096
|
const extendingConfig = extending.tsconfig;
|
|
1314
1097
|
const extendedConfig = extended.tsconfig;
|
|
1315
1098
|
const relativePath = util_native2posix(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].relative(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(extending.tsconfigFile), __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(extended.tsconfigFile)));
|
|
@@ -1326,11 +1109,9 @@ const EXTENDABLE_KEYS = [
|
|
|
1326
1109
|
}
|
|
1327
1110
|
}
|
|
1328
1111
|
const REBASE_KEYS = [
|
|
1329
|
-
// root
|
|
1330
1112
|
'files',
|
|
1331
1113
|
'include',
|
|
1332
1114
|
'exclude',
|
|
1333
|
-
// compilerOptions
|
|
1334
1115
|
'baseUrl',
|
|
1335
1116
|
'rootDir',
|
|
1336
1117
|
'rootDirs',
|
|
@@ -1338,53 +1119,24 @@ const REBASE_KEYS = [
|
|
|
1338
1119
|
'outDir',
|
|
1339
1120
|
'outFile',
|
|
1340
1121
|
'declarationDir',
|
|
1341
|
-
// watchOptions
|
|
1342
1122
|
'excludeDirectories',
|
|
1343
1123
|
'excludeFiles'
|
|
1344
1124
|
];
|
|
1345
|
-
|
|
1346
|
-
*
|
|
1347
|
-
* @param {string} key
|
|
1348
|
-
* @param {PathValue} value
|
|
1349
|
-
* @param {string} prependPath
|
|
1350
|
-
* @returns {PathValue}
|
|
1351
|
-
*/ function rebaseRelative(key, value, prependPath) {
|
|
1125
|
+
function rebaseRelative(key, value, prependPath) {
|
|
1352
1126
|
if (!REBASE_KEYS.includes(key)) return value;
|
|
1353
1127
|
if (Array.isArray(value)) return value.map((x)=>rebasePath(x, prependPath));
|
|
1354
1128
|
return rebasePath(value, prependPath);
|
|
1355
1129
|
}
|
|
1356
|
-
|
|
1357
|
-
*
|
|
1358
|
-
* @param {string} value
|
|
1359
|
-
* @param {string} prependPath
|
|
1360
|
-
* @returns {string}
|
|
1361
|
-
*/ function rebasePath(value, prependPath) {
|
|
1130
|
+
function rebasePath(value, prependPath) {
|
|
1362
1131
|
if (__WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(value) || value.startsWith('${configDir}')) return value;
|
|
1363
|
-
// relative paths use posix syntax in tsconfig
|
|
1364
1132
|
return __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.normalize(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.join(prependPath, value));
|
|
1365
1133
|
}
|
|
1366
1134
|
class TSConfckParseError extends Error {
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
/**
|
|
1372
|
-
* error cause
|
|
1373
|
-
* @type { Error | undefined}
|
|
1374
|
-
*/ cause;
|
|
1375
|
-
/**
|
|
1376
|
-
* absolute path of tsconfig file where the error happened
|
|
1377
|
-
* @type {string}
|
|
1378
|
-
*/ tsconfigFile;
|
|
1379
|
-
/**
|
|
1380
|
-
*
|
|
1381
|
-
* @param {string} message - error message
|
|
1382
|
-
* @param {string} code - error code
|
|
1383
|
-
* @param {string} tsconfigFile - path to tsconfig file
|
|
1384
|
-
* @param {Error?} cause - cause of this error
|
|
1385
|
-
*/ constructor(message, code, tsconfigFile, cause){
|
|
1135
|
+
code;
|
|
1136
|
+
cause;
|
|
1137
|
+
tsconfigFile;
|
|
1138
|
+
constructor(message, code, tsconfigFile, cause){
|
|
1386
1139
|
super(message);
|
|
1387
|
-
// Set the prototype explicitly.
|
|
1388
1140
|
Object.setPrototypeOf(this, TSConfckParseError.prototype);
|
|
1389
1141
|
this.name = TSConfckParseError.name;
|
|
1390
1142
|
this.code = code;
|
|
@@ -1392,11 +1144,7 @@ class TSConfckParseError extends Error {
|
|
|
1392
1144
|
this.tsconfigFile = tsconfigFile;
|
|
1393
1145
|
}
|
|
1394
1146
|
}
|
|
1395
|
-
|
|
1396
|
-
*
|
|
1397
|
-
* @param {any} tsconfig
|
|
1398
|
-
* @param {string} tsconfigFile
|
|
1399
|
-
*/ function applyDefaults(tsconfig, tsconfigFile) {
|
|
1147
|
+
function applyDefaults(tsconfig, tsconfigFile) {
|
|
1400
1148
|
if (isJSConfig(tsconfigFile)) tsconfig.compilerOptions = {
|
|
1401
1149
|
...DEFAULT_JSCONFIG_COMPILER_OPTIONS,
|
|
1402
1150
|
...tsconfig.compilerOptions
|
|
@@ -1409,9 +1157,7 @@ const DEFAULT_JSCONFIG_COMPILER_OPTIONS = {
|
|
|
1409
1157
|
skipLibCheck: true,
|
|
1410
1158
|
noEmit: true
|
|
1411
1159
|
};
|
|
1412
|
-
|
|
1413
|
-
* @param {string} configFileName
|
|
1414
|
-
*/ function isJSConfig(configFileName) {
|
|
1160
|
+
function isJSConfig(configFileName) {
|
|
1415
1161
|
return 'jsconfig.json' === __WEBPACK_EXTERNAL_MODULE_node_path__["default"].basename(configFileName);
|
|
1416
1162
|
}
|
|
1417
1163
|
async function loadTsconfig(root, tsconfigPath = 'tsconfig.json') {
|
|
@@ -1455,9 +1201,7 @@ const composeExternalsWarnConfig = (format, ...externalsArray)=>{
|
|
|
1455
1201
|
if ('esm' !== format) return {};
|
|
1456
1202
|
const externals = [];
|
|
1457
1203
|
for (const e of externalsArray.filter(Boolean))if (Array.isArray(e)) externals.push(...e);
|
|
1458
|
-
else
|
|
1459
|
-
externals.push(e);
|
|
1460
|
-
// Match logic is derived from https://github.com/webpack/webpack/blob/94aba382eccf3de1004d235045d4462918dfdbb7/lib/ExternalModuleFactoryPlugin.js#L166-L293.
|
|
1204
|
+
else externals.push(e);
|
|
1461
1205
|
const matchUserExternals = (externals, request, callback)=>{
|
|
1462
1206
|
if ('string' == typeof externals) {
|
|
1463
1207
|
if (externals === request) {
|
|
@@ -1519,16 +1263,15 @@ const composeExternalsWarnConfig = (format, ...externalsArray)=>{
|
|
|
1519
1263
|
}
|
|
1520
1264
|
};
|
|
1521
1265
|
};
|
|
1266
|
+
const getAutoExternalDefaultValue = (format, autoExternal)=>autoExternal ?? isIntermediateOutputFormat(format);
|
|
1522
1267
|
const composeAutoExternalConfig = (options)=>{
|
|
1523
|
-
const {
|
|
1524
|
-
|
|
1268
|
+
const { format, pkgJson, userExternals } = options;
|
|
1269
|
+
const autoExternal = getAutoExternalDefaultValue(format, options.autoExternal);
|
|
1270
|
+
if (false === autoExternal) return {};
|
|
1525
1271
|
if (!pkgJson) {
|
|
1526
1272
|
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn('autoExternal configuration will not be applied due to read package.json failed');
|
|
1527
1273
|
return {};
|
|
1528
1274
|
}
|
|
1529
|
-
// User externals configuration has higher priority than autoExternal
|
|
1530
|
-
// eg: autoExternal: ['react'], user: output: { externals: { react: 'react-1' } }
|
|
1531
|
-
// Only handle the case where the externals type is object, string / string[] does not need to be processed, other types are too complex.
|
|
1532
1275
|
const userExternalKeys = userExternals && isObject(userExternals) ? Object.keys(userExternals) : [];
|
|
1533
1276
|
const externalOptions = {
|
|
1534
1277
|
dependencies: true,
|
|
@@ -1550,7 +1293,6 @@ const composeAutoExternalConfig = (options)=>{
|
|
|
1550
1293
|
return externals.length ? {
|
|
1551
1294
|
output: {
|
|
1552
1295
|
externals: [
|
|
1553
|
-
// Exclude dependencies, e.g. `react`, `react/jsx-runtime`
|
|
1554
1296
|
...uniqueExternals.map((dep)=>new RegExp(`^${dep}($|\\/|\\\\)`)),
|
|
1555
1297
|
...uniqueExternals
|
|
1556
1298
|
]
|
|
@@ -1560,10 +1302,7 @@ const composeAutoExternalConfig = (options)=>{
|
|
|
1560
1302
|
function composeMinifyConfig(config) {
|
|
1561
1303
|
const minify = config.output?.minify;
|
|
1562
1304
|
const format = config.format;
|
|
1563
|
-
if (void 0 !== minify)
|
|
1564
|
-
return {};
|
|
1565
|
-
// When minify is not specified, Rslib will use a sane default for minify options.
|
|
1566
|
-
// The default options will only perform dead code elimination and unused code elimination.
|
|
1305
|
+
if (void 0 !== minify) return {};
|
|
1567
1306
|
return {
|
|
1568
1307
|
output: {
|
|
1569
1308
|
minify: {
|
|
@@ -1572,17 +1311,16 @@ function composeMinifyConfig(config) {
|
|
|
1572
1311
|
jsOptions: {
|
|
1573
1312
|
minimizerOptions: {
|
|
1574
1313
|
mangle: false,
|
|
1575
|
-
// MF assets are loaded over the network, which means they will not be compressed by the project. Therefore, minifying them is necessary.
|
|
1576
1314
|
minify: 'mf' === format,
|
|
1577
1315
|
compress: {
|
|
1578
1316
|
defaults: false,
|
|
1579
1317
|
unused: true,
|
|
1580
1318
|
dead_code: true,
|
|
1581
|
-
// remoteEntry's global variable will be tree-shaken if `toplevel` is enabled in "mf" format
|
|
1582
1319
|
toplevel: 'mf' !== format
|
|
1583
1320
|
},
|
|
1584
1321
|
format: {
|
|
1585
|
-
comments: '
|
|
1322
|
+
comments: 'some',
|
|
1323
|
+
preserve_annotations: true
|
|
1586
1324
|
}
|
|
1587
1325
|
}
|
|
1588
1326
|
}
|
|
@@ -1665,7 +1403,6 @@ async function createConstantRsbuildConfig() {
|
|
|
1665
1403
|
rspack: {
|
|
1666
1404
|
optimization: {
|
|
1667
1405
|
splitChunks: {
|
|
1668
|
-
// Splitted "sync" chunks will make entry modules can't be inlined.
|
|
1669
1406
|
chunks: 'async'
|
|
1670
1407
|
},
|
|
1671
1408
|
moduleIds: 'named',
|
|
@@ -1678,8 +1415,6 @@ async function createConstantRsbuildConfig() {
|
|
|
1678
1415
|
}
|
|
1679
1416
|
}
|
|
1680
1417
|
},
|
|
1681
|
-
// TypeScript-specific behavior: if the extension is ".js" or ".jsx", try replacing it with ".ts" or ".tsx"
|
|
1682
|
-
// see https://github.com/web-infra-dev/rslib/issues/41
|
|
1683
1418
|
resolve: {
|
|
1684
1419
|
extensionAlias: {
|
|
1685
1420
|
'.js': [
|
|
@@ -1823,8 +1558,6 @@ const composeFormatConfig = ({ format, bundle = true, umdName, pkgJson })=>{
|
|
|
1823
1558
|
output: {
|
|
1824
1559
|
uniqueName: pkgJson.name
|
|
1825
1560
|
},
|
|
1826
|
-
// can not set nodeEnv to false, because mf format should build shared module.
|
|
1827
|
-
// If nodeEnv is false, the process.env.NODE_ENV in third-party packages's will not be replaced
|
|
1828
1561
|
optimization: {
|
|
1829
1562
|
nodeEnv: 'production',
|
|
1830
1563
|
moduleIds: 'deterministic'
|
|
@@ -1843,8 +1576,6 @@ const formatRsbuildPlugin = ()=>({
|
|
|
1843
1576
|
name: 'rsbuild:format',
|
|
1844
1577
|
setup (api) {
|
|
1845
1578
|
api.modifyBundlerChain((config, { CHAIN_ID })=>{
|
|
1846
|
-
// Fix for https://github.com/web-infra-dev/rslib/issues/499.
|
|
1847
|
-
// Prevent parsing and try bundling `new URL()` in ESM format.
|
|
1848
1579
|
config.module.rule(CHAIN_ID.RULE.JS).parser({
|
|
1849
1580
|
url: false
|
|
1850
1581
|
});
|
|
@@ -1879,7 +1610,6 @@ const composeShimsConfig = (format, shims)=>{
|
|
|
1879
1610
|
tools: {
|
|
1880
1611
|
rspack: {
|
|
1881
1612
|
node: {
|
|
1882
|
-
// "__dirname" and "__filename" shims will automatically be enabled when `output.module` is `true`
|
|
1883
1613
|
__dirname: !!resolvedShims.esm.__dirname && 'node-module',
|
|
1884
1614
|
__filename: !!resolvedShims.esm.__filename && 'node-module'
|
|
1885
1615
|
}
|
|
@@ -1911,16 +1641,10 @@ const composeShimsConfig = (format, shims)=>{
|
|
|
1911
1641
|
};
|
|
1912
1642
|
const composeModuleImportWarn = (request)=>`The externalized commonjs request ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].green(`"${request}"`)} will use ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].blue('"module"')} external type in ESM format. If you want to specify other external type, considering set the request and type with ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].blue('"output.externals"')}.`;
|
|
1913
1643
|
const composeExternalsConfig = (format, externals)=>{
|
|
1914
|
-
// TODO: Define the internal externals config in Rsbuild's externals instead
|
|
1915
|
-
// Rspack's externals as they will not be merged from different fields. All externals
|
|
1916
|
-
// should to be unified and merged together in the future.
|
|
1917
1644
|
const externalsTypeMap = {
|
|
1918
1645
|
esm: 'module-import',
|
|
1919
1646
|
cjs: 'commonjs-import',
|
|
1920
1647
|
umd: 'umd',
|
|
1921
|
-
// If use 'var', when projects import an external package like '@pkg', this will cause a syntax error such as 'var pkg = @pkg'.
|
|
1922
|
-
// If use 'umd', the judgement conditions may be affected by other packages that define variables like 'define'.
|
|
1923
|
-
// Therefore, we use 'global' to satisfy both web and node environments.
|
|
1924
1648
|
mf: 'global'
|
|
1925
1649
|
};
|
|
1926
1650
|
switch(format){
|
|
@@ -1964,7 +1688,6 @@ const composeAutoExtensionConfig = (config, autoExtension, pkgJson)=>{
|
|
|
1964
1688
|
};
|
|
1965
1689
|
};
|
|
1966
1690
|
const composeSyntaxConfig = (target, syntax)=>{
|
|
1967
|
-
// Defaults to ESNext, Rslib will assume all of the latest JavaScript and CSS features are supported.
|
|
1968
1691
|
if (syntax) return {
|
|
1969
1692
|
tools: {
|
|
1970
1693
|
rspack: (config)=>{
|
|
@@ -1985,7 +1708,6 @@ const composeSyntaxConfig = (target, syntax)=>{
|
|
|
1985
1708
|
}
|
|
1986
1709
|
},
|
|
1987
1710
|
output: {
|
|
1988
|
-
// If `syntax` is not defined, Rslib will try to determine by the `target`, with the last version of the target.
|
|
1989
1711
|
overrideBrowserslist: ESX_TO_BROWSERSLIST.esnext(target)
|
|
1990
1712
|
}
|
|
1991
1713
|
};
|
|
@@ -2015,36 +1737,24 @@ const composeEntryConfig = async (entries, bundle, root, cssModulesAuto)=>{
|
|
|
2015
1737
|
},
|
|
2016
1738
|
lcp: null
|
|
2017
1739
|
};
|
|
2018
|
-
// In bundleless mode, resolve glob patterns and convert them to entry object.
|
|
2019
1740
|
const resolvedEntries = {};
|
|
2020
1741
|
for (const key of Object.keys(entries)){
|
|
2021
1742
|
const entry = entries[key];
|
|
2022
|
-
// Entries in bundleless mode could be:
|
|
2023
|
-
// 1. A string of glob pattern: { entry: { index: 'src/*.ts' } }
|
|
2024
|
-
// 2. An array of glob patterns: { entry: { index: ['src/*.ts', 'src/*.tsx'] } }
|
|
2025
|
-
// Not supported for now: entry description object
|
|
2026
1743
|
const entryFiles = Array.isArray(entry) ? entry : 'string' == typeof entry ? [
|
|
2027
1744
|
entry
|
|
2028
1745
|
] : null;
|
|
2029
1746
|
if (!entryFiles) throw new Error('Entry can only be a string or an array of strings for now');
|
|
2030
|
-
// Turn entries in array into each separate entry.
|
|
2031
1747
|
const globEntryFiles = await (0, __WEBPACK_EXTERNAL_MODULE_tinyglobby__.glob)(entryFiles, {
|
|
2032
1748
|
cwd: root,
|
|
2033
1749
|
absolute: true
|
|
2034
1750
|
});
|
|
2035
|
-
// Filter the glob resolved entry files based on the allowed extensions
|
|
2036
1751
|
const resolvedEntryFiles = globEntryFiles.filter((file)=>ENTRY_EXTENSIONS_PATTERN.test(file));
|
|
2037
1752
|
if (0 === resolvedEntryFiles.length) throw new Error(`Cannot find ${resolvedEntryFiles}`);
|
|
2038
|
-
// Similar to `rootDir` in tsconfig and `outbase` in esbuild.
|
|
2039
1753
|
const lcp = await calcLongestCommonPath(resolvedEntryFiles);
|
|
2040
|
-
// Using the longest common path of all non-declaration input files by default.
|
|
2041
1754
|
const outBase = null === lcp ? root : lcp;
|
|
2042
1755
|
function getEntryName(file) {
|
|
2043
1756
|
const { dir, name } = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].parse(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].relative(outBase, file));
|
|
2044
|
-
// Entry filename contains nested path to preserve source directory structure.
|
|
2045
1757
|
const entryFileName = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(dir, name);
|
|
2046
|
-
// 1. we mark the global css files (which will generate empty js chunk in cssExtract), and deleteAsset in RemoveCssExtractAssetPlugin
|
|
2047
|
-
// 2. avoid the same name e.g: `index.ts` and `index.css`
|
|
2048
1758
|
if (isCssGlobalFile(file, cssModulesAuto)) return `${RSLIB_CSS_ENTRY_FLAG}/${entryFileName}`;
|
|
2049
1759
|
return entryFileName;
|
|
2050
1760
|
}
|
|
@@ -2065,47 +1775,59 @@ const composeEntryConfig = async (entries, bundle, root, cssModulesAuto)=>{
|
|
|
2065
1775
|
lcp
|
|
2066
1776
|
};
|
|
2067
1777
|
};
|
|
2068
|
-
const
|
|
2069
|
-
if (bundle) return {
|
|
2070
|
-
|
|
1778
|
+
const composeBundlelessExternalConfig = (jsExtension, redirect, cssModulesAuto, bundle)=>{
|
|
1779
|
+
if (bundle) return {
|
|
1780
|
+
config: {}
|
|
1781
|
+
};
|
|
1782
|
+
const isStyleRedirected = redirect.style ?? true;
|
|
1783
|
+
const jsRedirectPath = redirect.js?.path ?? true;
|
|
1784
|
+
const jsRedirectExtension = redirect.js?.extension ?? true;
|
|
1785
|
+
let resolver;
|
|
2071
1786
|
return {
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
1787
|
+
resolvedJsRedirect: {
|
|
1788
|
+
path: jsRedirectPath,
|
|
1789
|
+
extension: jsRedirectExtension
|
|
1790
|
+
},
|
|
1791
|
+
config: {
|
|
1792
|
+
output: {
|
|
1793
|
+
externals: [
|
|
1794
|
+
async (data, callback)=>{
|
|
1795
|
+
const { request, getResolve, context, contextInfo } = data;
|
|
1796
|
+
if (!request || !getResolve || !context || !contextInfo) return callback();
|
|
1797
|
+
if (!resolver) resolver = await getResolve();
|
|
1798
|
+
if (contextInfo.issuer) {
|
|
1799
|
+
let resolvedRequest = request;
|
|
1800
|
+
const cssExternal = cssExternalHandler(resolvedRequest, callback, jsExtension, cssModulesAuto, isStyleRedirected);
|
|
1801
|
+
if (false !== cssExternal) return cssExternal;
|
|
1802
|
+
if (jsRedirectPath) {
|
|
1803
|
+
try {
|
|
1804
|
+
resolvedRequest = await resolver(context, resolvedRequest);
|
|
1805
|
+
} catch (e) {
|
|
1806
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.debug(`Failed to resolve ${resolvedRequest} with resolver`);
|
|
1807
|
+
}
|
|
1808
|
+
resolvedRequest = normalizeSlash(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].relative(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(contextInfo.issuer), resolvedRequest));
|
|
1809
|
+
if ('.' !== resolvedRequest[0]) resolvedRequest = `./${resolvedRequest}`;
|
|
1810
|
+
}
|
|
1811
|
+
if (jsRedirectExtension) {
|
|
1812
|
+
const ext = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.extname)(resolvedRequest);
|
|
1813
|
+
if (ext) {
|
|
1814
|
+
if (!JS_EXTENSIONS_PATTERN.test(resolvedRequest)) return callback();
|
|
1815
|
+
resolvedRequest = resolvedRequest.replace(/\.[^.]+$/, jsExtension);
|
|
1816
|
+
} else resolvedRequest = `${resolvedRequest}${jsExtension}`;
|
|
1817
|
+
}
|
|
1818
|
+
return callback(void 0, resolvedRequest);
|
|
2095
1819
|
}
|
|
2096
|
-
|
|
1820
|
+
callback();
|
|
2097
1821
|
}
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
]
|
|
1822
|
+
]
|
|
1823
|
+
}
|
|
2101
1824
|
}
|
|
2102
1825
|
};
|
|
2103
1826
|
};
|
|
2104
1827
|
const composeDtsConfig = async (libConfig, dtsExtension)=>{
|
|
2105
|
-
const { autoExternal, banner, footer } = libConfig;
|
|
1828
|
+
const { format, autoExternal, banner, footer } = libConfig;
|
|
2106
1829
|
let { dts } = libConfig;
|
|
2107
1830
|
if (false === dts || void 0 === dts) return {};
|
|
2108
|
-
// DTS default to bundleless whether js is bundle or not
|
|
2109
1831
|
if (true === dts) dts = {
|
|
2110
1832
|
bundle: false
|
|
2111
1833
|
};
|
|
@@ -2113,23 +1835,21 @@ const composeDtsConfig = async (libConfig, dtsExtension)=>{
|
|
|
2113
1835
|
return {
|
|
2114
1836
|
plugins: [
|
|
2115
1837
|
pluginDts({
|
|
2116
|
-
// Only setting dts.bundle to true will generate the bundled d.ts.
|
|
2117
1838
|
bundle: dts?.bundle,
|
|
2118
1839
|
distPath: dts?.distPath,
|
|
2119
1840
|
build: dts?.build,
|
|
2120
1841
|
abortOnError: dts?.abortOnError,
|
|
2121
1842
|
dtsExtension: dts?.autoExtension ? dtsExtension : '.d.ts',
|
|
2122
|
-
autoExternal,
|
|
1843
|
+
autoExternal: getAutoExternalDefaultValue(format, autoExternal),
|
|
2123
1844
|
banner: banner?.dts,
|
|
2124
1845
|
footer: footer?.dts
|
|
2125
1846
|
})
|
|
2126
1847
|
]
|
|
2127
1848
|
};
|
|
2128
1849
|
};
|
|
2129
|
-
const composeTargetConfig = (
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
switch(defaultTarget){
|
|
1850
|
+
const composeTargetConfig = (userTarget, format)=>{
|
|
1851
|
+
const target = userTarget ?? ('mf' === format ? 'web' : 'node');
|
|
1852
|
+
switch(target){
|
|
2133
1853
|
case 'web':
|
|
2134
1854
|
return {
|
|
2135
1855
|
config: {
|
|
@@ -2141,7 +1861,8 @@ const composeTargetConfig = (target, format)=>{
|
|
|
2141
1861
|
}
|
|
2142
1862
|
}
|
|
2143
1863
|
},
|
|
2144
|
-
target: 'web'
|
|
1864
|
+
target: 'web',
|
|
1865
|
+
externalsConfig: {}
|
|
2145
1866
|
};
|
|
2146
1867
|
case 'node':
|
|
2147
1868
|
return {
|
|
@@ -2154,26 +1875,18 @@ const composeTargetConfig = (target, format)=>{
|
|
|
2154
1875
|
}
|
|
2155
1876
|
},
|
|
2156
1877
|
output: {
|
|
2157
|
-
// When output.target is 'node', Node.js's built-in will be treated as externals of type `node-commonjs`.
|
|
2158
|
-
// Simply override the built-in modules to make them external.
|
|
2159
|
-
// https://github.com/webpack/webpack/blob/dd44b206a9c50f4b4cb4d134e1a0bd0387b159a3/lib/node/NodeTargetPlugin.js#L81
|
|
2160
|
-
externals: nodeBuiltInModules,
|
|
2161
1878
|
target: 'node'
|
|
2162
1879
|
}
|
|
2163
1880
|
},
|
|
2164
|
-
target: 'node'
|
|
1881
|
+
target: 'node',
|
|
1882
|
+
externalsConfig: {
|
|
1883
|
+
output: {
|
|
1884
|
+
externals: nodeBuiltInModules
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
2165
1887
|
};
|
|
2166
|
-
// TODO: Support `neutral` target, however Rsbuild don't list it as an option in the target field.
|
|
2167
|
-
// case 'neutral':
|
|
2168
|
-
// return {
|
|
2169
|
-
// tools: {
|
|
2170
|
-
// rspack: {
|
|
2171
|
-
// target: ['web', 'node'],
|
|
2172
|
-
// },
|
|
2173
|
-
// },
|
|
2174
|
-
// };
|
|
2175
1888
|
default:
|
|
2176
|
-
throw new Error(`Unsupported platform: ${
|
|
1889
|
+
throw new Error(`Unsupported platform: ${target}`);
|
|
2177
1890
|
}
|
|
2178
1891
|
};
|
|
2179
1892
|
const composeExternalHelpersConfig = (externalHelpers, pkgJson)=>{
|
|
@@ -2204,14 +1917,13 @@ const composeExternalHelpersConfig = (externalHelpers, pkgJson)=>{
|
|
|
2204
1917
|
}
|
|
2205
1918
|
return defaultConfig;
|
|
2206
1919
|
};
|
|
2207
|
-
async function composeLibRsbuildConfig(config) {
|
|
2208
|
-
checkMFPlugin(config);
|
|
2209
|
-
// Get the absolute path of the root directory to align with Rsbuild's default behavior
|
|
1920
|
+
async function composeLibRsbuildConfig(config, sharedPlugins) {
|
|
1921
|
+
checkMFPlugin(config, sharedPlugins);
|
|
2210
1922
|
const rootPath = config.root ? getAbsolutePath(process.cwd(), config.root) : process.cwd();
|
|
2211
1923
|
const pkgJson = readPackageJson(rootPath);
|
|
2212
1924
|
const { compilerOptions } = await loadTsconfig(rootPath, config.source?.tsconfigPath);
|
|
2213
1925
|
const cssModulesAuto = config.output?.cssModules?.auto ?? true;
|
|
2214
|
-
const { format, shims, bundle = true, banner = {}, footer = {}, autoExtension = true, autoExternal
|
|
1926
|
+
const { format, shims, bundle = true, banner = {}, footer = {}, autoExtension = true, autoExternal, externalHelpers = false, redirect = {}, umdName } = config;
|
|
2215
1927
|
const { rsbuildConfig: shimsConfig, enabledShims } = composeShimsConfig(format, shims);
|
|
2216
1928
|
const formatConfig = composeFormatConfig({
|
|
2217
1929
|
format: format,
|
|
@@ -2220,55 +1932,43 @@ async function composeLibRsbuildConfig(config) {
|
|
|
2220
1932
|
umdName
|
|
2221
1933
|
});
|
|
2222
1934
|
const externalHelpersConfig = composeExternalHelpersConfig(externalHelpers, pkgJson);
|
|
2223
|
-
const
|
|
1935
|
+
const userExternalsConfig = composeExternalsConfig(format, config.output?.externals);
|
|
2224
1936
|
const { config: autoExtensionConfig, jsExtension, dtsExtension } = composeAutoExtensionConfig(config, autoExtension, pkgJson);
|
|
2225
|
-
const
|
|
2226
|
-
const { config: targetConfig, target } = composeTargetConfig(config.output?.target, format);
|
|
1937
|
+
const { config: bundlelessExternalConfig } = composeBundlelessExternalConfig(jsExtension, redirect, cssModulesAuto, bundle);
|
|
1938
|
+
const { config: targetConfig, externalsConfig: targetExternalsConfig, target } = composeTargetConfig(config.output?.target, format);
|
|
2227
1939
|
const syntaxConfig = composeSyntaxConfig(target, config?.syntax);
|
|
2228
1940
|
const autoExternalConfig = composeAutoExternalConfig({
|
|
1941
|
+
format: format,
|
|
2229
1942
|
autoExternal,
|
|
2230
1943
|
pkgJson,
|
|
2231
1944
|
userExternals: config.output?.externals
|
|
2232
1945
|
});
|
|
2233
1946
|
const { entryConfig, lcp } = await composeEntryConfig(config.source?.entry, config.bundle, rootPath, cssModulesAuto);
|
|
2234
1947
|
const cssConfig = composeCssConfig(lcp, config.bundle);
|
|
1948
|
+
const assetConfig = composeAssetConfig(bundle, format);
|
|
2235
1949
|
const entryChunkConfig = composeEntryChunkConfig({
|
|
2236
1950
|
enabledImportMetaUrlShim: enabledShims.cjs['import.meta.url']
|
|
2237
1951
|
});
|
|
2238
1952
|
const dtsConfig = await composeDtsConfig(config, dtsExtension);
|
|
2239
|
-
const externalsWarnConfig = composeExternalsWarnConfig(format, autoExternalConfig?.output?.externals,
|
|
1953
|
+
const externalsWarnConfig = composeExternalsWarnConfig(format, autoExternalConfig?.output?.externals, userExternalsConfig?.output?.externals);
|
|
2240
1954
|
const minifyConfig = composeMinifyConfig(config);
|
|
2241
1955
|
const bannerFooterConfig = composeBannerFooterConfig(banner, footer);
|
|
2242
1956
|
const decoratorsConfig = composeDecoratorsConfig(compilerOptions, config.source?.decorators?.version);
|
|
2243
|
-
return (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(formatConfig, shimsConfig, externalHelpersConfig,
|
|
1957
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(formatConfig, shimsConfig, syntaxConfig, externalHelpersConfig, autoExtensionConfig, targetConfig, externalsWarnConfig, autoExternalConfig, targetExternalsConfig, userExternalsConfig, bundlelessExternalConfig, entryConfig, cssConfig, assetConfig, entryChunkConfig, minifyConfig, dtsConfig, bannerFooterConfig, decoratorsConfig);
|
|
2244
1958
|
}
|
|
2245
1959
|
async function composeCreateRsbuildConfig(rslibConfig) {
|
|
2246
1960
|
const constantRsbuildConfig = await createConstantRsbuildConfig();
|
|
2247
|
-
const { lib: libConfigsArray, ...sharedRsbuildConfig } = rslibConfig;
|
|
1961
|
+
const { lib: libConfigsArray, plugins: sharedPlugins, ...sharedRsbuildConfig } = rslibConfig;
|
|
2248
1962
|
if (!libConfigsArray) throw new Error(`Expect lib field to be an array, but got ${libConfigsArray}.`);
|
|
2249
1963
|
const libConfigPromises = libConfigsArray.map(async (libConfig)=>{
|
|
2250
1964
|
const userConfig = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(sharedRsbuildConfig, libConfig);
|
|
2251
|
-
|
|
2252
|
-
// configuration and Lib configuration in the settings.
|
|
2253
|
-
const libRsbuildConfig = await composeLibRsbuildConfig(userConfig);
|
|
2254
|
-
// Reset certain fields because they will be completely overridden by the upcoming merge.
|
|
2255
|
-
// We don't want to retain them in the final configuration.
|
|
2256
|
-
// The reset process should occur after merging the library configuration.
|
|
1965
|
+
const libRsbuildConfig = await composeLibRsbuildConfig(userConfig, sharedPlugins);
|
|
2257
1966
|
userConfig.source ??= {};
|
|
2258
1967
|
userConfig.source.entry = {};
|
|
2259
|
-
// Already manually sort and merge the externals configuration.
|
|
2260
1968
|
userConfig.output ??= {};
|
|
2261
1969
|
delete userConfig.output.externals;
|
|
2262
1970
|
const config = {
|
|
2263
1971
|
format: libConfig.format,
|
|
2264
|
-
// The merge order represents the priority of the configuration
|
|
2265
|
-
// The priorities from high to low are as follows:
|
|
2266
|
-
// 1 - userConfig: users can configure any Rsbuild and Rspack config
|
|
2267
|
-
// 2 - libRsbuildConfig: the configuration that we compose from Rslib unique config and userConfig from 1
|
|
2268
|
-
// 3 - constantRsbuildConfig: the built-in best practice Rsbuild configuration we provide in Rslib
|
|
2269
|
-
// We should state in the document that the built-in configuration should not be changed optionally
|
|
2270
|
-
// In compose process of 2, we may read some config from 1, and reassemble the related config,
|
|
2271
|
-
// so before final mergeRsbuildConfig, we reset some specified fields
|
|
2272
1972
|
config: (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(constantRsbuildConfig, libRsbuildConfig, omit(userConfig, {
|
|
2273
1973
|
id: true,
|
|
2274
1974
|
bundle: true,
|
|
@@ -2293,7 +1993,6 @@ async function composeCreateRsbuildConfig(rslibConfig) {
|
|
|
2293
1993
|
}
|
|
2294
1994
|
async function composeRsbuildEnvironments(rslibConfig) {
|
|
2295
1995
|
const rsbuildConfigWithLibInfo = await composeCreateRsbuildConfig(rslibConfig);
|
|
2296
|
-
// User provided ids should take precedence over generated ids.
|
|
2297
1996
|
const usedIds = rsbuildConfigWithLibInfo.map(({ id })=>id).filter(Boolean);
|
|
2298
1997
|
const environments = {};
|
|
2299
1998
|
const formatCount = rsbuildConfigWithLibInfo.reduce((acc, { format })=>{
|
|
@@ -2325,7 +2024,6 @@ async function watchFilesForRestart(files, restart) {
|
|
|
2325
2024
|
const chokidar = await import("../compiled/chokidar/index.js");
|
|
2326
2025
|
const watcher = chokidar.watch(files, {
|
|
2327
2026
|
ignoreInitial: true,
|
|
2328
|
-
// If watching fails due to read permissions, the errors will be suppressed silently.
|
|
2329
2027
|
ignorePermissionErrors: true
|
|
2330
2028
|
});
|
|
2331
2029
|
const callback = debounce(async (filePath)=>{
|
|
@@ -2340,9 +2038,7 @@ async function watchFilesForRestart(files, restart) {
|
|
|
2340
2038
|
watcher.on('unlink', callback);
|
|
2341
2039
|
}
|
|
2342
2040
|
let cleaners = [];
|
|
2343
|
-
|
|
2344
|
-
* Add a cleaner to handle side effects
|
|
2345
|
-
*/ const onBeforeRestart = (cleaner)=>{
|
|
2041
|
+
const onBeforeRestart = (cleaner)=>{
|
|
2346
2042
|
cleaners.push(cleaner);
|
|
2347
2043
|
};
|
|
2348
2044
|
const clearConsole = ()=>{
|
|
@@ -2361,6 +2057,7 @@ async function build(config, options = {}) {
|
|
|
2361
2057
|
const environments = await composeRsbuildEnvironments(config);
|
|
2362
2058
|
const rsbuildInstance = await (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.createRsbuild)({
|
|
2363
2059
|
rsbuildConfig: {
|
|
2060
|
+
plugins: config.plugins,
|
|
2364
2061
|
environments: pruneEnvironments(environments, options.lib)
|
|
2365
2062
|
}
|
|
2366
2063
|
});
|
|
@@ -2407,6 +2104,7 @@ async function inspect(config, options = {}) {
|
|
|
2407
2104
|
const environments = await composeRsbuildEnvironments(config);
|
|
2408
2105
|
const rsbuildInstance = await (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.createRsbuild)({
|
|
2409
2106
|
rsbuildConfig: {
|
|
2107
|
+
plugins: config.plugins,
|
|
2410
2108
|
environments: pruneEnvironments(environments, options.lib)
|
|
2411
2109
|
}
|
|
2412
2110
|
});
|
|
@@ -2425,11 +2123,16 @@ async function startMFDevServer(config) {
|
|
|
2425
2123
|
async function initMFRsbuild(rslibConfig) {
|
|
2426
2124
|
const rsbuildConfigObject = await composeCreateRsbuildConfig(rslibConfig);
|
|
2427
2125
|
const mfRsbuildConfig = rsbuildConfigObject.find((config)=>'mf' === config.format);
|
|
2428
|
-
if (!mfRsbuildConfig)
|
|
2429
|
-
return;
|
|
2126
|
+
if (!mfRsbuildConfig) return;
|
|
2430
2127
|
mfRsbuildConfig.config = changeEnvToDev(mfRsbuildConfig.config);
|
|
2431
2128
|
const rsbuildInstance = await (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.createRsbuild)({
|
|
2432
|
-
rsbuildConfig:
|
|
2129
|
+
rsbuildConfig: {
|
|
2130
|
+
...mfRsbuildConfig.config,
|
|
2131
|
+
plugins: [
|
|
2132
|
+
...rslibConfig.plugins || [],
|
|
2133
|
+
...mfRsbuildConfig.config.plugins || []
|
|
2134
|
+
]
|
|
2135
|
+
}
|
|
2433
2136
|
});
|
|
2434
2137
|
const devServer = await rsbuildInstance.startDevServer();
|
|
2435
2138
|
onBeforeRestart(devServer.server.close);
|
|
@@ -2458,7 +2161,7 @@ const repeatableOption = (value, previous)=>(previous ?? []).concat([
|
|
|
2458
2161
|
value
|
|
2459
2162
|
]);
|
|
2460
2163
|
function runCli() {
|
|
2461
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.name('rslib').usage('<command> [options]').version("0.1.
|
|
2164
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.name('rslib').usage('<command> [options]').version("0.1.5");
|
|
2462
2165
|
const buildCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('build');
|
|
2463
2166
|
const inspectCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('inspect');
|
|
2464
2167
|
const mfDevCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('mf dev');
|
|
@@ -2485,7 +2188,6 @@ function runCli() {
|
|
|
2485
2188
|
});
|
|
2486
2189
|
inspectCommand.description('inspect the Rsbuild / Rspack configs of Rslib projects').option('--lib <id>', 'inspect the specified library (may be repeated)', repeatableOption).option('--output <output>', 'specify inspect content output path', '.rsbuild').option('--verbose', 'show full function definitions in output').action(async (options)=>{
|
|
2487
2190
|
try {
|
|
2488
|
-
// TODO: inspect should output Rslib's config
|
|
2489
2191
|
const { config } = await init(options);
|
|
2490
2192
|
await inspect(config, {
|
|
2491
2193
|
lib: options.lib,
|
|
@@ -2503,7 +2205,6 @@ function runCli() {
|
|
|
2503
2205
|
try {
|
|
2504
2206
|
const cliMfDev = async ()=>{
|
|
2505
2207
|
const { config, watchFiles } = await init(options);
|
|
2506
|
-
// TODO: support lib option in mf dev server
|
|
2507
2208
|
await startMFDevServer(config);
|
|
2508
2209
|
watchFilesForRestart(watchFiles, async ()=>{
|
|
2509
2210
|
await cliMfDev();
|
|
@@ -2518,6 +2219,6 @@ function runCli() {
|
|
|
2518
2219
|
});
|
|
2519
2220
|
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.parse();
|
|
2520
2221
|
}
|
|
2521
|
-
const src_rslib_entry_version = "0.1.
|
|
2222
|
+
const src_rslib_entry_version = "0.1.5";
|
|
2522
2223
|
var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger;
|
|
2523
2224
|
export { build, defineConfig, inspect, loadConfig, prepareCli, runCli, startMFDevServer, composeCreateRsbuildConfig as unstable_composeCreateRsbuildConfig, src_rslib_entry_version as version, __webpack_exports__logger as logger };
|