@rslib/core 0.0.6 → 0.0.7
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/index.js +196 -113
- package/dist-types/constant.d.ts +6 -1
- package/dist-types/plugins/cjsShim.d.ts +2 -0
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -7,11 +7,6 @@ import * as __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__ from "../co
|
|
|
7
7
|
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core__ from "@rsbuild/core";
|
|
8
8
|
import * as __WEBPACK_EXTERNAL_MODULE__compiled_fast_glob_index_js__ from "../compiled/fast-glob/index.js";
|
|
9
9
|
import * as __WEBPACK_EXTERNAL_MODULE_module__ from "module";
|
|
10
|
-
var index_js_namespaceObject = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__;
|
|
11
|
-
var external_node_fs_namespaceObject = __WEBPACK_EXTERNAL_MODULE_node_fs__;
|
|
12
|
-
var promises_namespaceObject = __WEBPACK_EXTERNAL_MODULE_node_fs_promises__;
|
|
13
|
-
var external_node_path_namespaceObject = __WEBPACK_EXTERNAL_MODULE_node_path__;
|
|
14
|
-
var picocolors_index_js_namespaceObject = __WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__;
|
|
15
10
|
/**
|
|
16
11
|
* Node.js built-in modules.
|
|
17
12
|
* Copied from https://github.com/webpack/webpack/blob/dd44b206a9c50f4b4cb4d134e1a0bd0387b159a3/lib/node/NodeTargetPlugin.js#L12-L72
|
|
@@ -80,7 +75,7 @@ async function calcLongestCommonPath(absPaths) {
|
|
|
80
75
|
// we support two cases
|
|
81
76
|
// 1. /packages-a/src/index.ts
|
|
82
77
|
// 2. D:/packages-a/src/index.ts
|
|
83
|
-
const sep =
|
|
78
|
+
const sep = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep;
|
|
84
79
|
const splitPaths = absPaths.map((p)=>p.split(sep));
|
|
85
80
|
let lcaFragments = splitPaths[0];
|
|
86
81
|
for(let i = 1; i < splitPaths.length; i++){
|
|
@@ -91,20 +86,20 @@ async function calcLongestCommonPath(absPaths) {
|
|
|
91
86
|
lcaFragments = lcaFragments.slice(0, j);
|
|
92
87
|
}
|
|
93
88
|
let lca = lcaFragments.length > 0 ? lcaFragments.join(sep) : sep;
|
|
94
|
-
const stats = await
|
|
95
|
-
if (stats?.isFile()) lca =
|
|
89
|
+
const stats = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises__["default"].stat(lca);
|
|
90
|
+
if (stats?.isFile()) lca = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(lca);
|
|
96
91
|
return lca;
|
|
97
92
|
}
|
|
98
93
|
const readPackageJson = (rootPath)=>{
|
|
99
|
-
const pkgJsonPath =
|
|
100
|
-
if (!
|
|
101
|
-
|
|
94
|
+
const pkgJsonPath = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(rootPath, './package.json');
|
|
95
|
+
if (!__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync(pkgJsonPath)) {
|
|
96
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn(`package.json does not exist in the ${rootPath} directory`);
|
|
102
97
|
return;
|
|
103
98
|
}
|
|
104
99
|
try {
|
|
105
|
-
return JSON.parse(
|
|
100
|
+
return JSON.parse(__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].readFileSync(pkgJsonPath, 'utf8'));
|
|
106
101
|
} catch (err) {
|
|
107
|
-
|
|
102
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn(`Failed to parse ${pkgJsonPath}, it might not be valid JSON`);
|
|
108
103
|
return;
|
|
109
104
|
}
|
|
110
105
|
};
|
|
@@ -123,7 +118,7 @@ function omit(obj, keys) {
|
|
|
123
118
|
}, {});
|
|
124
119
|
}
|
|
125
120
|
// setup the logger level
|
|
126
|
-
if (process.env.DEBUG)
|
|
121
|
+
if (process.env.DEBUG) __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.level = 'verbose';
|
|
127
122
|
function initNodeEnv() {
|
|
128
123
|
if (!process.env.NODE_ENV) {
|
|
129
124
|
const command = process.argv[2] ?? '';
|
|
@@ -138,13 +133,10 @@ function prepareCli() {
|
|
|
138
133
|
// Some package managers automatically output a blank line, some do not.
|
|
139
134
|
const { npm_execpath } = process.env;
|
|
140
135
|
if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
|
|
141
|
-
|
|
136
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rslib v0.0.7\n`);
|
|
142
137
|
}
|
|
143
|
-
var commander_index_js_namespaceObject = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__;
|
|
144
|
-
var core_namespaceObject = __WEBPACK_EXTERNAL_MODULE__rsbuild_core__;
|
|
145
|
-
var fast_glob_index_js_namespaceObject = __WEBPACK_EXTERNAL_MODULE__compiled_fast_glob_index_js__;
|
|
146
138
|
const DEFAULT_CONFIG_NAME = 'rslib.config';
|
|
147
|
-
const
|
|
139
|
+
const DEFAULT_CONFIG_EXTENSIONS = [
|
|
148
140
|
'.js',
|
|
149
141
|
'.ts',
|
|
150
142
|
'.mjs',
|
|
@@ -153,6 +145,66 @@ const DEFAULT_EXTENSIONS = [
|
|
|
153
145
|
'.cts'
|
|
154
146
|
];
|
|
155
147
|
const SWC_HELPERS = '@swc/helpers';
|
|
148
|
+
const JS_EXTENSIONS = [
|
|
149
|
+
'js',
|
|
150
|
+
'mjs',
|
|
151
|
+
'jsx',
|
|
152
|
+
'ts',
|
|
153
|
+
'mts',
|
|
154
|
+
'tsx',
|
|
155
|
+
'cjs',
|
|
156
|
+
'cjsx',
|
|
157
|
+
'mjsx',
|
|
158
|
+
'mtsx',
|
|
159
|
+
'cts',
|
|
160
|
+
'ctsx'
|
|
161
|
+
];
|
|
162
|
+
const CSS_EXTENSIONS = [
|
|
163
|
+
'css',
|
|
164
|
+
'sass',
|
|
165
|
+
'scss',
|
|
166
|
+
'less'
|
|
167
|
+
];
|
|
168
|
+
const ENTRY_EXTENSIONS = [
|
|
169
|
+
...JS_EXTENSIONS,
|
|
170
|
+
...CSS_EXTENSIONS
|
|
171
|
+
];
|
|
172
|
+
const JS_EXTENSIONS_PATTERN = new RegExp(`\\.(${JS_EXTENSIONS.join('|')})$`);
|
|
173
|
+
const ENTRY_EXTENSIONS_PATTERN = new RegExp(`\\.(${ENTRY_EXTENSIONS.join('|')})$`);
|
|
174
|
+
const importMetaUrlShim = `var __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
175
|
+
return typeof document === 'undefined'
|
|
176
|
+
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
177
|
+
: (document.currentScript && document.currentScript.src) ||
|
|
178
|
+
new URL('main.js', document.baseURI).href;
|
|
179
|
+
})();
|
|
180
|
+
`;
|
|
181
|
+
// This Rsbuild plugin will shim `import.meta.url` for CommonJS modules.
|
|
182
|
+
// - Replace `import.meta.url` with `importMetaUrl`.
|
|
183
|
+
// - Inject `importMetaUrl` to the end of the module (can't inject at the beginning because of `"use strict";`).
|
|
184
|
+
// This is a short-term solution, and we hope to provide built-in polyfills like `node.__filename` on Rspack side.
|
|
185
|
+
const pluginCjsShim = ()=>({
|
|
186
|
+
name: 'rsbuild-plugin-cjs-shim',
|
|
187
|
+
setup (api) {
|
|
188
|
+
api.modifyRsbuildConfig((config)=>{
|
|
189
|
+
config.source ||= {};
|
|
190
|
+
config.source.define = {
|
|
191
|
+
...config.source.define,
|
|
192
|
+
'import.meta.url': '__rslib_import_meta_url__'
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
api.modifyRspackConfig((config)=>{
|
|
196
|
+
config.plugins ??= [];
|
|
197
|
+
config.plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.BannerPlugin({
|
|
198
|
+
banner: importMetaUrlShim,
|
|
199
|
+
// Just before minify stage, to perform tree shaking.
|
|
200
|
+
stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE - 1,
|
|
201
|
+
raw: true,
|
|
202
|
+
footer: true,
|
|
203
|
+
include: /\.(js|cjs)$/
|
|
204
|
+
}));
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
});
|
|
156
208
|
const getDefaultExtension = (options)=>{
|
|
157
209
|
const { format, pkgJson, autoExtension } = options;
|
|
158
210
|
let jsExtension = '.js';
|
|
@@ -162,7 +214,7 @@ const getDefaultExtension = (options)=>{
|
|
|
162
214
|
dtsExtension
|
|
163
215
|
};
|
|
164
216
|
if (!pkgJson) {
|
|
165
|
-
|
|
217
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn('autoExtension configuration will not be applied due to read package.json failed');
|
|
166
218
|
return {
|
|
167
219
|
jsExtension,
|
|
168
220
|
dtsExtension
|
|
@@ -345,8 +397,8 @@ function transformSyntaxToBrowserslist(syntax, target) {
|
|
|
345
397
|
if (Array.isArray(syntax)) return syntax.flatMap(handleSyntaxItem);
|
|
346
398
|
return handleSyntaxItem(syntax);
|
|
347
399
|
}
|
|
348
|
-
const POSIX_SEP_RE = new RegExp('\\' +
|
|
349
|
-
const NATIVE_SEP_RE = new RegExp('\\' +
|
|
400
|
+
const POSIX_SEP_RE = new RegExp('\\' + __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep, 'g');
|
|
401
|
+
const NATIVE_SEP_RE = new RegExp('\\' + __WEBPACK_EXTERNAL_MODULE_node_path__["default"].sep, 'g');
|
|
350
402
|
/** @type {Map<string,RegExp>}*/ const PATTERN_REGEX_CACHE = new Map();
|
|
351
403
|
const GLOB_ALL_PATTERN = "**/*";
|
|
352
404
|
const TS_EXTENSIONS = [
|
|
@@ -355,16 +407,16 @@ const TS_EXTENSIONS = [
|
|
|
355
407
|
'.mts',
|
|
356
408
|
'.cts'
|
|
357
409
|
];
|
|
358
|
-
const
|
|
410
|
+
const util_JS_EXTENSIONS = [
|
|
359
411
|
'.js',
|
|
360
412
|
'.jsx',
|
|
361
413
|
'.mjs',
|
|
362
414
|
'.cjs'
|
|
363
415
|
];
|
|
364
|
-
const TSJS_EXTENSIONS = TS_EXTENSIONS.concat(
|
|
416
|
+
const TSJS_EXTENSIONS = TS_EXTENSIONS.concat(util_JS_EXTENSIONS);
|
|
365
417
|
const TS_EXTENSIONS_RE_GROUP = `\\.(?:${TS_EXTENSIONS.map((ext)=>ext.substring(1)).join('|')})`;
|
|
366
418
|
const TSJS_EXTENSIONS_RE_GROUP = `\\.(?:${TSJS_EXTENSIONS.map((ext)=>ext.substring(1)).join('|')})`;
|
|
367
|
-
const IS_POSIX =
|
|
419
|
+
const IS_POSIX = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep === __WEBPACK_EXTERNAL_MODULE_node_path__["default"].sep;
|
|
368
420
|
/**
|
|
369
421
|
* @template T
|
|
370
422
|
* @returns {{resolve:(result:T)=>void, reject:(error:any)=>void, promise: Promise<T>}}
|
|
@@ -385,10 +437,10 @@ const IS_POSIX = external_node_path_namespaceObject["default"].posix.sep === ext
|
|
|
385
437
|
* @param {import('./cache.js').TSConfckCache} [cache]
|
|
386
438
|
* @returns {Promise<string|void>}
|
|
387
439
|
*/ async function util_resolveTSConfigJson(filename, cache) {
|
|
388
|
-
if ('.json' !==
|
|
389
|
-
const tsconfig =
|
|
440
|
+
if ('.json' !== __WEBPACK_EXTERNAL_MODULE_node_path__["default"].extname(filename)) return; // ignore files that are not json
|
|
441
|
+
const tsconfig = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(filename);
|
|
390
442
|
if (cache && (cache.hasParseResult(tsconfig) || cache.hasParseResult(filename))) return tsconfig;
|
|
391
|
-
return
|
|
443
|
+
return __WEBPACK_EXTERNAL_MODULE_node_fs__.promises.stat(tsconfig).then((stat)=>{
|
|
392
444
|
if (stat.isFile() || stat.isFIFO()) return tsconfig;
|
|
393
445
|
throw new Error(`${filename} exists but is not a regular file.`);
|
|
394
446
|
});
|
|
@@ -407,7 +459,7 @@ const IS_POSIX = external_node_path_namespaceObject["default"].posix.sep === ext
|
|
|
407
459
|
*
|
|
408
460
|
* @param {string} filename with posix separators
|
|
409
461
|
* @returns {string} filename with native separators
|
|
410
|
-
*/ const posix2native = IS_POSIX ? (filename)=>filename : (filename)=>filename.replace(POSIX_SEP_RE,
|
|
462
|
+
*/ const posix2native = IS_POSIX ? (filename)=>filename : (filename)=>filename.replace(POSIX_SEP_RE, __WEBPACK_EXTERNAL_MODULE_node_path__["default"].sep);
|
|
411
463
|
/**
|
|
412
464
|
* convert native separator to posix separator
|
|
413
465
|
*
|
|
@@ -417,7 +469,7 @@ const IS_POSIX = external_node_path_namespaceObject["default"].posix.sep === ext
|
|
|
417
469
|
*
|
|
418
470
|
* @param {string} filename - filename with native separators
|
|
419
471
|
* @returns {string} filename with posix separators
|
|
420
|
-
*/ const util_native2posix = IS_POSIX ? (filename)=>filename : (filename)=>filename.replace(NATIVE_SEP_RE,
|
|
472
|
+
*/ const util_native2posix = IS_POSIX ? (filename)=>filename : (filename)=>filename.replace(NATIVE_SEP_RE, __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.sep);
|
|
421
473
|
/**
|
|
422
474
|
* converts params to native separator, resolves path and converts native back to posix
|
|
423
475
|
*
|
|
@@ -426,16 +478,16 @@ const IS_POSIX = external_node_path_namespaceObject["default"].posix.sep === ext
|
|
|
426
478
|
* @param dir {string|null} directory to resolve from
|
|
427
479
|
* @param filename {string} filename or pattern to resolve
|
|
428
480
|
* @returns string
|
|
429
|
-
*/ const resolve2posix = IS_POSIX ? (dir, filename)=>dir ?
|
|
481
|
+
*/ 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)));
|
|
430
482
|
/**
|
|
431
483
|
*
|
|
432
484
|
* @param {import('./public.d.ts').TSConfckParseResult} result
|
|
433
485
|
* @param {import('./public.d.ts').TSConfckParseOptions} [options]
|
|
434
486
|
* @returns {string[]}
|
|
435
487
|
*/ function util_resolveReferencedTSConfigFiles(result, options) {
|
|
436
|
-
const dir =
|
|
488
|
+
const dir = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(result.tsconfigFile);
|
|
437
489
|
return result.tsconfig.references.map((ref)=>{
|
|
438
|
-
const refPath = ref.path.endsWith('.json') ? ref.path :
|
|
490
|
+
const refPath = ref.path.endsWith('.json') ? ref.path : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(ref.path, options?.configName ?? 'tsconfig.json');
|
|
439
491
|
return resolve2posix(dir, refPath);
|
|
440
492
|
});
|
|
441
493
|
}
|
|
@@ -458,7 +510,7 @@ const IS_POSIX = external_node_path_namespaceObject["default"].posix.sep === ext
|
|
|
458
510
|
* @param {import('./public.d.ts').TSConfckParseResult} result
|
|
459
511
|
* @returns {boolean}
|
|
460
512
|
*/ function util_isIncluded(filename, result) {
|
|
461
|
-
const dir = util_native2posix(
|
|
513
|
+
const dir = util_native2posix(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(result.tsconfigFile));
|
|
462
514
|
const files = (result.tsconfig.files || []).map((file)=>resolve2posix(dir, file));
|
|
463
515
|
const absoluteFilename = resolve2posix(null, filename);
|
|
464
516
|
if (files.includes(filename)) return true;
|
|
@@ -560,13 +612,13 @@ const IS_POSIX = external_node_path_namespaceObject["default"].posix.sep === ext
|
|
|
560
612
|
* @param {import('./public.d.ts').TSConfckFindOptions} [options] - options
|
|
561
613
|
* @returns {Promise<string|null>} absolute path to closest tsconfig.json or null if not found
|
|
562
614
|
*/ async function find(filename, options) {
|
|
563
|
-
let dir =
|
|
615
|
+
let dir = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(filename));
|
|
564
616
|
if (options?.ignoreNodeModules && util_isInNodeModules(dir)) return null;
|
|
565
617
|
const cache = options?.cache;
|
|
566
618
|
const configName = options?.configName ?? 'tsconfig.json';
|
|
567
619
|
if (cache?.hasConfigPath(dir, configName)) return cache.getConfigPath(dir, configName);
|
|
568
620
|
const { promise, resolve, reject } = util_makePromise();
|
|
569
|
-
if (options?.root && !
|
|
621
|
+
if (options?.root && !__WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(options.root)) options.root = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(options.root);
|
|
570
622
|
findUp(dir, {
|
|
571
623
|
promise,
|
|
572
624
|
resolve,
|
|
@@ -594,13 +646,13 @@ const IS_POSIX = external_node_path_namespaceObject["default"].posix.sep === ext
|
|
|
594
646
|
else resolve(cached);
|
|
595
647
|
} else cache.setConfigPath(dir, promise, configName);
|
|
596
648
|
}
|
|
597
|
-
const tsconfig =
|
|
598
|
-
|
|
649
|
+
const tsconfig = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(dir, options?.configName ?? 'tsconfig.json');
|
|
650
|
+
__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].stat(tsconfig, (err, stats)=>{
|
|
599
651
|
if (stats && (stats.isFile() || stats.isFIFO())) resolve(tsconfig);
|
|
600
652
|
else if (err?.code !== 'ENOENT') reject(err);
|
|
601
653
|
else {
|
|
602
654
|
let parent;
|
|
603
|
-
if (root === dir || (parent =
|
|
655
|
+
if (root === dir || (parent = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(dir)) === dir) resolve(null);
|
|
604
656
|
else findUp(parent, {
|
|
605
657
|
promise,
|
|
606
658
|
resolve,
|
|
@@ -617,7 +669,7 @@ const IS_POSIX = external_node_path_namespaceObject["default"].posix.sep === ext
|
|
|
617
669
|
* @property {(dir: string)=>boolean} skip - function to skip dirs
|
|
618
670
|
* @property {boolean} err - error flag
|
|
619
671
|
* @property {string[]} configNames - config file names
|
|
620
|
-
*/
|
|
672
|
+
*/ __WEBPACK_EXTERNAL_MODULE_node_path__["default"].sep;
|
|
621
673
|
/*
|
|
622
674
|
this file contains code from strip-bom and strip-json-comments by Sindre Sorhus
|
|
623
675
|
https://github.com/sindresorhus/strip-json-comments/blob/v4.0.0/index.js
|
|
@@ -752,7 +804,6 @@ const multiComment = Symbol('multiComment');
|
|
|
752
804
|
if (0xfeff === string.charCodeAt(0)) return string.slice(1);
|
|
753
805
|
return string;
|
|
754
806
|
}
|
|
755
|
-
var external_module_namespaceObject = __WEBPACK_EXTERNAL_MODULE_module__;
|
|
756
807
|
const not_found_result = {
|
|
757
808
|
tsconfigFile: null,
|
|
758
809
|
tsconfig: {}
|
|
@@ -784,7 +835,7 @@ const not_found_result = {
|
|
|
784
835
|
parseReferences(result, options)
|
|
785
836
|
]);
|
|
786
837
|
}
|
|
787
|
-
result.tsconfig = util_replaceTokens(result.tsconfig,
|
|
838
|
+
result.tsconfig = util_replaceTokens(result.tsconfig, __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(tsconfigFile));
|
|
788
839
|
resolve(util_resolveSolutionTSConfig(filename, result));
|
|
789
840
|
} catch (e) {
|
|
790
841
|
reject(e);
|
|
@@ -817,12 +868,12 @@ const not_found_result = {
|
|
|
817
868
|
* @returns {Promise<import('./public.d.ts').TSConfckParseResult>}
|
|
818
869
|
*/ async function parseFile(tsconfigFile, cache, skipCache) {
|
|
819
870
|
if (!skipCache && cache?.hasParseResult(tsconfigFile) && !cache.getParseResult(tsconfigFile)._isRootFile_) return cache.getParseResult(tsconfigFile);
|
|
820
|
-
const promise =
|
|
871
|
+
const promise = __WEBPACK_EXTERNAL_MODULE_node_fs__.promises.readFile(tsconfigFile, 'utf-8').then(toJson).then((json)=>{
|
|
821
872
|
const parsed = JSON.parse(json);
|
|
822
873
|
applyDefaults(parsed, tsconfigFile);
|
|
823
874
|
return {
|
|
824
875
|
tsconfigFile,
|
|
825
|
-
tsconfig: normalizeTSConfig(parsed,
|
|
876
|
+
tsconfig: normalizeTSConfig(parsed, __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(tsconfigFile))
|
|
826
877
|
};
|
|
827
878
|
}).catch((e)=>{
|
|
828
879
|
throw new TSConfckParseError(`parsing ${tsconfigFile} failed: ${e}`, 'PARSE_FILE', tsconfigFile, e);
|
|
@@ -838,7 +889,7 @@ const not_found_result = {
|
|
|
838
889
|
*/ function normalizeTSConfig(tsconfig, dir) {
|
|
839
890
|
// set baseUrl to absolute path
|
|
840
891
|
const baseUrl = tsconfig.compilerOptions?.baseUrl;
|
|
841
|
-
if (baseUrl && !baseUrl.startsWith('${') && !
|
|
892
|
+
if (baseUrl && !baseUrl.startsWith('${') && !__WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(baseUrl)) tsconfig.compilerOptions.baseUrl = resolve2posix(dir, baseUrl);
|
|
842
893
|
return tsconfig;
|
|
843
894
|
}
|
|
844
895
|
/**
|
|
@@ -913,14 +964,14 @@ const not_found_result = {
|
|
|
913
964
|
*/ function resolveExtends(extended, from) {
|
|
914
965
|
if ('..' === extended) // see #149
|
|
915
966
|
extended = '../tsconfig.json';
|
|
916
|
-
const req = (0,
|
|
967
|
+
const req = (0, __WEBPACK_EXTERNAL_MODULE_module__.createRequire)(from);
|
|
917
968
|
let error;
|
|
918
969
|
try {
|
|
919
970
|
return req.resolve(extended);
|
|
920
971
|
} catch (e) {
|
|
921
972
|
error = e;
|
|
922
973
|
}
|
|
923
|
-
if ('.' !== extended[0] && !
|
|
974
|
+
if ('.' !== extended[0] && !__WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(extended)) try {
|
|
924
975
|
return req.resolve(`${extended}/tsconfig.json`);
|
|
925
976
|
} catch (e) {
|
|
926
977
|
error = e;
|
|
@@ -946,7 +997,7 @@ const EXTENDABLE_KEYS = [
|
|
|
946
997
|
*/ function extendTSConfig(extending, extended) {
|
|
947
998
|
const extendingConfig = extending.tsconfig;
|
|
948
999
|
const extendedConfig = extended.tsconfig;
|
|
949
|
-
const relativePath = util_native2posix(
|
|
1000
|
+
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)));
|
|
950
1001
|
for (const key of Object.keys(extendedConfig).filter((key)=>EXTENDABLE_KEYS.includes(key)))if ('compilerOptions' === key) {
|
|
951
1002
|
if (!extendingConfig.compilerOptions) extendingConfig.compilerOptions = {};
|
|
952
1003
|
for (const option of Object.keys(extendedConfig.compilerOptions)){
|
|
@@ -993,9 +1044,9 @@ const REBASE_KEYS = [
|
|
|
993
1044
|
* @param {string} prependPath
|
|
994
1045
|
* @returns {string}
|
|
995
1046
|
*/ function rebasePath(value, prependPath) {
|
|
996
|
-
if (
|
|
1047
|
+
if (__WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(value) || value.startsWith('${configDir}')) return value;
|
|
997
1048
|
// relative paths use posix syntax in tsconfig
|
|
998
|
-
return
|
|
1049
|
+
return __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.normalize(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.join(prependPath, value));
|
|
999
1050
|
}
|
|
1000
1051
|
class TSConfckParseError extends Error {
|
|
1001
1052
|
/**
|
|
@@ -1046,12 +1097,12 @@ const DEFAULT_JSCONFIG_COMPILER_OPTIONS = {
|
|
|
1046
1097
|
/**
|
|
1047
1098
|
* @param {string} configFileName
|
|
1048
1099
|
*/ function isJSConfig(configFileName) {
|
|
1049
|
-
return 'jsconfig.json' ===
|
|
1100
|
+
return 'jsconfig.json' === __WEBPACK_EXTERNAL_MODULE_node_path__["default"].basename(configFileName);
|
|
1050
1101
|
}
|
|
1051
1102
|
async function loadTsconfig(root, tsconfigPath = 'tsconfig.json') {
|
|
1052
|
-
const tsconfigFileName = await find((0,
|
|
1103
|
+
const tsconfigFileName = await find((0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(root, tsconfigPath), {
|
|
1053
1104
|
root,
|
|
1054
|
-
configName: (0,
|
|
1105
|
+
configName: (0, __WEBPACK_EXTERNAL_MODULE_node_path__.basename)(tsconfigPath)
|
|
1055
1106
|
});
|
|
1056
1107
|
if (tsconfigFileName) {
|
|
1057
1108
|
const { tsconfig } = await parse(tsconfigFileName);
|
|
@@ -1065,21 +1116,21 @@ async function loadTsconfig(root, tsconfigPath = 'tsconfig.json') {
|
|
|
1065
1116
|
*/ function defineConfig(config) {
|
|
1066
1117
|
return config;
|
|
1067
1118
|
}
|
|
1068
|
-
const findConfig = (basePath)=>
|
|
1119
|
+
const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync);
|
|
1069
1120
|
const resolveConfigPath = (root, customConfig)=>{
|
|
1070
1121
|
if (customConfig) {
|
|
1071
|
-
const customConfigPath = (0,
|
|
1072
|
-
if (
|
|
1073
|
-
|
|
1122
|
+
const customConfigPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.isAbsolute)(customConfig) ? customConfig : (0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(root, customConfig);
|
|
1123
|
+
if (__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync(customConfigPath)) return customConfigPath;
|
|
1124
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn(`Cannot find config file: ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].dim(customConfigPath)}\n`);
|
|
1074
1125
|
}
|
|
1075
|
-
const configFilePath = findConfig((0,
|
|
1126
|
+
const configFilePath = findConfig((0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(root, DEFAULT_CONFIG_NAME));
|
|
1076
1127
|
if (configFilePath) return configFilePath;
|
|
1077
1128
|
throw new Error(`${DEFAULT_CONFIG_NAME} not found in ${root}`);
|
|
1078
1129
|
};
|
|
1079
1130
|
async function loadConfig({ cwd = process.cwd(), path, envMode }) {
|
|
1080
1131
|
const configFilePath = resolveConfigPath(cwd, path);
|
|
1081
|
-
const { content } = await (0,
|
|
1082
|
-
cwd: (0,
|
|
1132
|
+
const { content } = await (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.loadConfig)({
|
|
1133
|
+
cwd: (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(configFilePath),
|
|
1083
1134
|
path: configFilePath,
|
|
1084
1135
|
envMode
|
|
1085
1136
|
});
|
|
@@ -1145,7 +1196,7 @@ const composeExternalsWarnConfig = (format, ...externalsArray)=>{
|
|
|
1145
1196
|
};
|
|
1146
1197
|
if (contextInfo.issuer && 'commonjs' === dependencyType) {
|
|
1147
1198
|
matchUserExternals(externals, request, _callback);
|
|
1148
|
-
if (externalized)
|
|
1199
|
+
if (externalized) __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn(composeModuleImportWarn(request));
|
|
1149
1200
|
}
|
|
1150
1201
|
callback();
|
|
1151
1202
|
}
|
|
@@ -1157,7 +1208,7 @@ const composeAutoExternalConfig = (options)=>{
|
|
|
1157
1208
|
const { autoExternal, pkgJson, userExternals } = options;
|
|
1158
1209
|
if (!autoExternal) return {};
|
|
1159
1210
|
if (!pkgJson) {
|
|
1160
|
-
|
|
1211
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.warn('autoExternal configuration will not be applied due to read package.json failed');
|
|
1161
1212
|
return {};
|
|
1162
1213
|
}
|
|
1163
1214
|
const externalOptions = {
|
|
@@ -1230,30 +1281,30 @@ function composeBannerFooterConfig(banner, footer) {
|
|
|
1230
1281
|
if (isEmptyObject(bannerConfig) && isEmptyObject(footerConfig)) return {};
|
|
1231
1282
|
const plugins = [];
|
|
1232
1283
|
if (!isEmptyObject(bannerConfig)) {
|
|
1233
|
-
if (bannerConfig.js) plugins.push(new
|
|
1284
|
+
if (bannerConfig.js) plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.BannerPlugin({
|
|
1234
1285
|
banner: bannerConfig.js,
|
|
1235
|
-
stage:
|
|
1286
|
+
stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
|
|
1236
1287
|
raw: true,
|
|
1237
1288
|
include: /\.(js|mjs|cjs)$/
|
|
1238
1289
|
}));
|
|
1239
|
-
if (bannerConfig.css) plugins.push(new
|
|
1290
|
+
if (bannerConfig.css) plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.BannerPlugin({
|
|
1240
1291
|
banner: bannerConfig.css,
|
|
1241
|
-
stage:
|
|
1292
|
+
stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
|
|
1242
1293
|
raw: true,
|
|
1243
1294
|
include: /\.(css)$/
|
|
1244
1295
|
}));
|
|
1245
1296
|
}
|
|
1246
1297
|
if (!isEmptyObject(footerConfig)) {
|
|
1247
|
-
if (footerConfig.js) plugins.push(new
|
|
1298
|
+
if (footerConfig.js) plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.BannerPlugin({
|
|
1248
1299
|
banner: footerConfig.js,
|
|
1249
|
-
stage:
|
|
1300
|
+
stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
|
|
1250
1301
|
raw: true,
|
|
1251
1302
|
footer: true,
|
|
1252
1303
|
include: /\.(js|mjs|cjs)$/
|
|
1253
1304
|
}));
|
|
1254
|
-
if (footerConfig.css) plugins.push(new
|
|
1305
|
+
if (footerConfig.css) plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.BannerPlugin({
|
|
1255
1306
|
banner: footerConfig.css,
|
|
1256
|
-
stage:
|
|
1307
|
+
stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
|
|
1257
1308
|
raw: true,
|
|
1258
1309
|
footer: true,
|
|
1259
1310
|
include: /\.(css)$/
|
|
@@ -1278,7 +1329,7 @@ function composeDecoratorsConfig(compilerOptions, version) {
|
|
|
1278
1329
|
};
|
|
1279
1330
|
}
|
|
1280
1331
|
async function createConstantRsbuildConfig() {
|
|
1281
|
-
return (0,
|
|
1332
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.defineConfig)({
|
|
1282
1333
|
mode: 'production',
|
|
1283
1334
|
dev: {
|
|
1284
1335
|
progressBar: false
|
|
@@ -1362,8 +1413,18 @@ const composeFormatConfig = (format)=>{
|
|
|
1362
1413
|
};
|
|
1363
1414
|
case 'cjs':
|
|
1364
1415
|
return {
|
|
1416
|
+
plugins: [
|
|
1417
|
+
pluginCjsShim()
|
|
1418
|
+
],
|
|
1365
1419
|
tools: {
|
|
1366
1420
|
rspack: {
|
|
1421
|
+
module: {
|
|
1422
|
+
parser: {
|
|
1423
|
+
javascript: {
|
|
1424
|
+
importMeta: false
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
},
|
|
1367
1428
|
output: {
|
|
1368
1429
|
iife: false,
|
|
1369
1430
|
chunkFormat: 'commonjs',
|
|
@@ -1378,6 +1439,13 @@ const composeFormatConfig = (format)=>{
|
|
|
1378
1439
|
return {
|
|
1379
1440
|
tools: {
|
|
1380
1441
|
rspack: {
|
|
1442
|
+
module: {
|
|
1443
|
+
parser: {
|
|
1444
|
+
javascript: {
|
|
1445
|
+
importMeta: false
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
},
|
|
1381
1449
|
output: {
|
|
1382
1450
|
library: {
|
|
1383
1451
|
type: 'umd'
|
|
@@ -1390,7 +1458,7 @@ const composeFormatConfig = (format)=>{
|
|
|
1390
1458
|
throw new Error(`Unsupported format: ${format}`);
|
|
1391
1459
|
}
|
|
1392
1460
|
};
|
|
1393
|
-
const composeModuleImportWarn = (request)=>`The externalized commonjs request ${
|
|
1461
|
+
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"')}.`;
|
|
1394
1462
|
const composeExternalsConfig = (format, externals)=>{
|
|
1395
1463
|
// TODO: Define the internal externals config in Rsbuild's externals instead
|
|
1396
1464
|
// Rspack's externals as they will not be merged from different fields. All externals
|
|
@@ -1439,22 +1507,19 @@ const composeAutoExtensionConfig = (config, autoExtension, pkgJson)=>{
|
|
|
1439
1507
|
};
|
|
1440
1508
|
const composeSyntaxConfig = (syntax, target)=>{
|
|
1441
1509
|
// Defaults to ESNext, Rslib will assume all of the latest JavaScript and CSS features are supported.
|
|
1442
|
-
if (syntax)
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1510
|
+
if (syntax) {
|
|
1511
|
+
const resolvedBrowserslist = transformSyntaxToBrowserslist(syntax, target);
|
|
1512
|
+
return {
|
|
1513
|
+
tools: {
|
|
1514
|
+
rspack: (config)=>{
|
|
1515
|
+
config.target = resolvedBrowserslist.map((item)=>`browserslist:${item}`);
|
|
1516
|
+
}
|
|
1517
|
+
},
|
|
1518
|
+
output: {
|
|
1519
|
+
overrideBrowserslist: resolvedBrowserslist
|
|
1452
1520
|
}
|
|
1453
|
-
}
|
|
1454
|
-
|
|
1455
|
-
overrideBrowserslist: transformSyntaxToBrowserslist(syntax, target)
|
|
1456
|
-
}
|
|
1457
|
-
};
|
|
1521
|
+
};
|
|
1522
|
+
}
|
|
1458
1523
|
return {
|
|
1459
1524
|
tools: {
|
|
1460
1525
|
rspack: (config)=>{
|
|
@@ -1490,18 +1555,20 @@ const composeEntryConfig = async (entries, bundle, root)=>{
|
|
|
1490
1555
|
] : null;
|
|
1491
1556
|
if (!entryFiles) throw new Error('Entry can only be a string or an array of strings for now');
|
|
1492
1557
|
// Turn entries in array into each separate entry.
|
|
1493
|
-
const
|
|
1558
|
+
const globEntryFiles = await (0, __WEBPACK_EXTERNAL_MODULE__compiled_fast_glob_index_js__["default"])(entryFiles, {
|
|
1494
1559
|
cwd: root
|
|
1495
1560
|
});
|
|
1561
|
+
// Filter the glob resolved entry files based on the allowed extensions
|
|
1562
|
+
const resolvedEntryFiles = globEntryFiles.filter((file)=>ENTRY_EXTENSIONS_PATTERN.test(file));
|
|
1496
1563
|
if (0 === resolvedEntryFiles.length) throw new Error(`Cannot find ${resolvedEntryFiles}`);
|
|
1497
1564
|
// Similar to `rootDir` in tsconfig and `outbase` in esbuild.
|
|
1498
1565
|
const lcp = await calcLongestCommonPath(resolvedEntryFiles);
|
|
1499
1566
|
// Using the longest common path of all non-declaration input files by default.
|
|
1500
1567
|
const outBase = null === lcp ? root : lcp;
|
|
1501
1568
|
for (const file of resolvedEntryFiles){
|
|
1502
|
-
const { dir, name } =
|
|
1569
|
+
const { dir, name } = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].parse(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].relative(outBase, file));
|
|
1503
1570
|
// Entry filename contains nested path to preserve source directory structure.
|
|
1504
|
-
const entryFileName =
|
|
1571
|
+
const entryFileName = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(dir, name);
|
|
1505
1572
|
resolvedEntries[entryFileName] = file;
|
|
1506
1573
|
}
|
|
1507
1574
|
}
|
|
@@ -1527,7 +1594,13 @@ const composeBundleConfig = (jsExtension, bundle = true)=>{
|
|
|
1527
1594
|
// This may result in a change in semantics,
|
|
1528
1595
|
// user should use copy to keep origin file or use another separate entry to deal this
|
|
1529
1596
|
let request = data.request;
|
|
1530
|
-
if ('.' === request[0])
|
|
1597
|
+
if ('.' === request[0]) {
|
|
1598
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE_node_path__.extname)(request)) {
|
|
1599
|
+
if (!JS_EXTENSIONS_PATTERN.test(request)) // If it does not match jsExtensionsPattern, we should do nothing, eg: ./foo.png
|
|
1600
|
+
return callback();
|
|
1601
|
+
request = request.replace(/\.[^.]+$/, jsExtension);
|
|
1602
|
+
} else request = `${request}${jsExtension}`;
|
|
1603
|
+
}
|
|
1531
1604
|
return callback(null, request);
|
|
1532
1605
|
}
|
|
1533
1606
|
callback();
|
|
@@ -1562,7 +1635,12 @@ const composeTargetConfig = (target = 'web')=>{
|
|
|
1562
1635
|
rspack: {
|
|
1563
1636
|
target: [
|
|
1564
1637
|
'web'
|
|
1565
|
-
]
|
|
1638
|
+
],
|
|
1639
|
+
output: {
|
|
1640
|
+
chunkLoading: 'import',
|
|
1641
|
+
workerChunkLoading: 'import',
|
|
1642
|
+
wasmLoading: 'fetch'
|
|
1643
|
+
}
|
|
1566
1644
|
}
|
|
1567
1645
|
}
|
|
1568
1646
|
};
|
|
@@ -1572,12 +1650,17 @@ const composeTargetConfig = (target = 'web')=>{
|
|
|
1572
1650
|
rspack: {
|
|
1573
1651
|
target: [
|
|
1574
1652
|
'node'
|
|
1575
|
-
]
|
|
1653
|
+
],
|
|
1654
|
+
// "__dirname" and "__filename" shims will automatically be enabled when `output.module` is `true`,
|
|
1655
|
+
// and leave them as-is in the rest of the cases.
|
|
1656
|
+
// { node: { __dirname: ..., __filename: ... } }
|
|
1657
|
+
output: {
|
|
1658
|
+
chunkLoading: 'require',
|
|
1659
|
+
workerChunkLoading: 'async-node',
|
|
1660
|
+
wasmLoading: 'async-node'
|
|
1661
|
+
}
|
|
1576
1662
|
}
|
|
1577
1663
|
},
|
|
1578
|
-
// "__dirname" and "__filename" shims will automatically be enabled when `output.module` is `true`,
|
|
1579
|
-
// and leave them as-is in the rest of the cases.
|
|
1580
|
-
// { node: { __dirname: ..., __filename: ... } }
|
|
1581
1664
|
output: {
|
|
1582
1665
|
// When output.target is 'node', Node.js's built-in will be treated as externals of type `node-commonjs`.
|
|
1583
1666
|
// Simply override the built-in modules to make them external.
|
|
@@ -1615,7 +1698,7 @@ const composeExternalHelpersConfig = (externalHelpers, pkgJson)=>{
|
|
|
1615
1698
|
...Object.keys(pkgJson?.devDependencies ?? [])
|
|
1616
1699
|
];
|
|
1617
1700
|
if (!deps.includes(SWC_HELPERS)) {
|
|
1618
|
-
|
|
1701
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.error(`${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].green('externalHelpers')} is enabled, but the ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js__["default"].blue(SWC_HELPERS)} dependency declaration was not found in package.json.`);
|
|
1619
1702
|
process.exit(1);
|
|
1620
1703
|
}
|
|
1621
1704
|
defaultConfig = Object.assign(defaultConfig, {
|
|
@@ -1628,7 +1711,7 @@ const composeExternalHelpersConfig = (externalHelpers, pkgJson)=>{
|
|
|
1628
1711
|
return defaultConfig;
|
|
1629
1712
|
};
|
|
1630
1713
|
async function composeLibRsbuildConfig(config, configPath) {
|
|
1631
|
-
const rootPath = (0,
|
|
1714
|
+
const rootPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(configPath);
|
|
1632
1715
|
const pkgJson = readPackageJson(rootPath);
|
|
1633
1716
|
const { compilerOptions } = await loadTsconfig(rootPath, config.source?.tsconfigPath);
|
|
1634
1717
|
const { format, banner = {}, footer = {}, autoExtension = true, autoExternal = true, externalHelpers = false } = config;
|
|
@@ -1644,13 +1727,13 @@ async function composeLibRsbuildConfig(config, configPath) {
|
|
|
1644
1727
|
pkgJson,
|
|
1645
1728
|
userExternals: config.output?.externals
|
|
1646
1729
|
});
|
|
1647
|
-
const entryConfig = await composeEntryConfig(config.source?.entry, config.bundle, (0,
|
|
1730
|
+
const entryConfig = await composeEntryConfig(config.source?.entry, config.bundle, (0, __WEBPACK_EXTERNAL_MODULE_node_path__.dirname)(configPath));
|
|
1648
1731
|
const dtsConfig = await composeDtsConfig(config, dtsExtension);
|
|
1649
1732
|
const externalsWarnConfig = composeExternalsWarnConfig(format, autoExternalConfig?.output?.externals, externalsConfig?.output?.externals);
|
|
1650
1733
|
const minifyConfig = composeMinifyConfig(config.output?.minify);
|
|
1651
1734
|
const bannerFooterConfig = composeBannerFooterConfig(banner, footer);
|
|
1652
1735
|
const decoratorsConfig = composeDecoratorsConfig(compilerOptions, config.source?.decorators?.version);
|
|
1653
|
-
return (0,
|
|
1736
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(formatConfig, externalHelpersConfig, externalsWarnConfig, externalsConfig, autoExternalConfig, autoExtensionConfig, syntaxConfig, bundleConfig, targetConfig, entryConfig, minifyConfig, dtsConfig, bannerFooterConfig, decoratorsConfig);
|
|
1654
1737
|
}
|
|
1655
1738
|
async function composeCreateRsbuildConfig(rslibConfig, path) {
|
|
1656
1739
|
const constantRsbuildConfig = await createConstantRsbuildConfig();
|
|
@@ -1658,7 +1741,7 @@ async function composeCreateRsbuildConfig(rslibConfig, path) {
|
|
|
1658
1741
|
const { lib: libConfigsArray, ...sharedRsbuildConfig } = rslibConfig;
|
|
1659
1742
|
if (!libConfigsArray) throw new Error(`Expect lib field to be an array, but got ${libConfigsArray}.`);
|
|
1660
1743
|
const libConfigPromises = libConfigsArray.map(async (libConfig)=>{
|
|
1661
|
-
const userConfig = (0,
|
|
1744
|
+
const userConfig = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(sharedRsbuildConfig, libConfig);
|
|
1662
1745
|
// Merge the configuration of each environment based on the shared Rsbuild
|
|
1663
1746
|
// configuration and Lib configuration in the settings.
|
|
1664
1747
|
const libRsbuildConfig = await composeLibRsbuildConfig(userConfig, configPath);
|
|
@@ -1680,7 +1763,7 @@ async function composeCreateRsbuildConfig(rslibConfig, path) {
|
|
|
1680
1763
|
// We should state in the document that the built-in configuration should not be changed optionally
|
|
1681
1764
|
// In compose process of 2, we may read some config from 1, and reassemble the related config,
|
|
1682
1765
|
// so before final mergeRsbuildConfig, we reset some specified fields
|
|
1683
|
-
config: (0,
|
|
1766
|
+
config: (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(constantRsbuildConfig, libRsbuildConfig, omit(userConfig, [
|
|
1684
1767
|
'bundle',
|
|
1685
1768
|
'format',
|
|
1686
1769
|
'autoExtension',
|
|
@@ -1713,7 +1796,7 @@ async function initRsbuild(rslibConfig) {
|
|
|
1713
1796
|
const currentFormatIndex = formatIndex[format]++;
|
|
1714
1797
|
environments[1 === currentFormatCount ? format : `${format}${currentFormatIndex}`] = config;
|
|
1715
1798
|
}
|
|
1716
|
-
return (0,
|
|
1799
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.createRsbuild)({
|
|
1717
1800
|
rsbuildConfig: {
|
|
1718
1801
|
environments
|
|
1719
1802
|
}
|
|
@@ -1730,9 +1813,9 @@ const applyCommonOptions = (command)=>{
|
|
|
1730
1813
|
command.option('-c --config <config>', 'specify the configuration file, can be a relative or absolute path').option('--env-mode <mode>', 'specify the env mode to load the `.env.[mode]` file');
|
|
1731
1814
|
};
|
|
1732
1815
|
function runCli() {
|
|
1733
|
-
|
|
1734
|
-
const buildCommand =
|
|
1735
|
-
const inspectCommand =
|
|
1816
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.name('rslib').usage('<command> [options]').version("0.0.7");
|
|
1817
|
+
const buildCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('build');
|
|
1818
|
+
const inspectCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('inspect');
|
|
1736
1819
|
[
|
|
1737
1820
|
buildCommand,
|
|
1738
1821
|
inspectCommand
|
|
@@ -1745,8 +1828,8 @@ function runCli() {
|
|
|
1745
1828
|
});
|
|
1746
1829
|
await build(rslibConfig, options);
|
|
1747
1830
|
} catch (err) {
|
|
1748
|
-
|
|
1749
|
-
|
|
1831
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.error('Failed to build.');
|
|
1832
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.error(err);
|
|
1750
1833
|
process.exit(1);
|
|
1751
1834
|
}
|
|
1752
1835
|
});
|
|
@@ -1765,13 +1848,13 @@ function runCli() {
|
|
|
1765
1848
|
writeToDisk: true
|
|
1766
1849
|
});
|
|
1767
1850
|
} catch (err) {
|
|
1768
|
-
|
|
1769
|
-
|
|
1851
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.error('Failed to inspect config.');
|
|
1852
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.error(err);
|
|
1770
1853
|
process.exit(1);
|
|
1771
1854
|
}
|
|
1772
1855
|
});
|
|
1773
|
-
|
|
1856
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.parse();
|
|
1774
1857
|
}
|
|
1775
|
-
const src_version = "0.0.
|
|
1776
|
-
var __webpack_exports__logger =
|
|
1858
|
+
const src_version = "0.0.7";
|
|
1859
|
+
var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger;
|
|
1777
1860
|
export { build, defineConfig, loadConfig, prepareCli, runCli, src_version as version, __webpack_exports__logger as logger };
|
package/dist-types/constant.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
export declare const DEFAULT_CONFIG_NAME = "rslib.config";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const DEFAULT_CONFIG_EXTENSIONS: readonly [".js", ".ts", ".mjs", ".mts", ".cjs", ".cts"];
|
|
3
3
|
export declare const SWC_HELPERS = "@swc/helpers";
|
|
4
|
+
export declare const JS_EXTENSIONS: string[];
|
|
5
|
+
export declare const CSS_EXTENSIONS: string[];
|
|
6
|
+
export declare const ENTRY_EXTENSIONS: string[];
|
|
7
|
+
export declare const JS_EXTENSIONS_PATTERN: RegExp;
|
|
8
|
+
export declare const ENTRY_EXTENSIONS_PATTERN: RegExp;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rslib/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "The Rspack-based library build tool.",
|
|
5
5
|
"homepage": "https://lib.rsbuild.dev",
|
|
6
6
|
"bugs": {
|
|
@@ -32,18 +32,18 @@
|
|
|
32
32
|
"compiled"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@rsbuild/core": "1.0.
|
|
36
|
-
"rsbuild-plugin-dts": "0.0.
|
|
35
|
+
"@rsbuild/core": "1.0.5",
|
|
36
|
+
"rsbuild-plugin-dts": "0.0.7"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/fs-extra": "^11.0.4",
|
|
40
40
|
"commander": "^12.1.0",
|
|
41
41
|
"fast-glob": "^3.3.2",
|
|
42
42
|
"fs-extra": "^11.2.0",
|
|
43
|
-
"memfs": "^4.
|
|
43
|
+
"memfs": "^4.12.0",
|
|
44
44
|
"picocolors": "1.1.0",
|
|
45
45
|
"prebundle": "1.2.2",
|
|
46
|
-
"rslib": "npm:@rslib/core@0.0.
|
|
46
|
+
"rslib": "npm:@rslib/core@0.0.6",
|
|
47
47
|
"rslog": "^1.2.3",
|
|
48
48
|
"tsconfck": "3.1.3",
|
|
49
49
|
"typescript": "^5.6.2",
|