@rslib/core 0.0.11 → 0.0.12
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
CHANGED
|
@@ -134,7 +134,7 @@ function prepareCli() {
|
|
|
134
134
|
// Some package managers automatically output a blank line, some do not.
|
|
135
135
|
const { npm_execpath } = process.env;
|
|
136
136
|
if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
|
|
137
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rslib v0.0.
|
|
137
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger.greet(` Rslib v0.0.12\n`);
|
|
138
138
|
}
|
|
139
139
|
const DEFAULT_CONFIG_NAME = 'rslib.config';
|
|
140
140
|
const DEFAULT_CONFIG_EXTENSIONS = [
|
|
@@ -291,7 +291,7 @@ const composeCssConfig = (rootDir, bundle = true)=>{
|
|
|
291
291
|
};
|
|
292
292
|
const importMetaUrlShim = `/*#__PURE__*/ (function () {
|
|
293
293
|
return typeof document === 'undefined'
|
|
294
|
-
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
294
|
+
? new (module.require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
295
295
|
: (document.currentScript && document.currentScript.src) ||
|
|
296
296
|
new URL('main.js', document.baseURI).href;
|
|
297
297
|
})()`;
|
|
@@ -299,8 +299,8 @@ const importMetaUrlShim = `/*#__PURE__*/ (function () {
|
|
|
299
299
|
// - Replace `import.meta.url` with `importMetaUrl`.
|
|
300
300
|
// - Inject `importMetaUrl` to the end of the module (can't inject at the beginning because of `"use strict";`).
|
|
301
301
|
// This is a short-term solution, and we hope to provide built-in polyfills like `node.__filename` on Rspack side.
|
|
302
|
-
const
|
|
303
|
-
name: 'rsbuild-
|
|
302
|
+
const pluginCjsImportMetaUrlShim = ()=>({
|
|
303
|
+
name: 'rsbuild:cjs-import-meta-url-shim',
|
|
304
304
|
setup (api) {
|
|
305
305
|
api.modifyEnvironmentConfig((config)=>{
|
|
306
306
|
config.source.define = {
|
|
@@ -310,6 +310,25 @@ const pluginCjsShim = ()=>({
|
|
|
310
310
|
});
|
|
311
311
|
}
|
|
312
312
|
});
|
|
313
|
+
const requireShim = `// Rslib ESM shims
|
|
314
|
+
import __rslib_shim_module__ from 'module';
|
|
315
|
+
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
|
|
316
|
+
`;
|
|
317
|
+
const pluginEsmRequireShim = ()=>({
|
|
318
|
+
name: 'rsbuild:esm-require-shim',
|
|
319
|
+
setup (api) {
|
|
320
|
+
api.modifyRspackConfig((config)=>{
|
|
321
|
+
config.plugins ??= [];
|
|
322
|
+
config.plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.BannerPlugin({
|
|
323
|
+
banner: requireShim,
|
|
324
|
+
// Just before minify stage, to perform tree shaking.
|
|
325
|
+
stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE - 1,
|
|
326
|
+
raw: true,
|
|
327
|
+
include: /\.(js|cjs)$/
|
|
328
|
+
}));
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
});
|
|
313
332
|
const getDefaultExtension = (options)=>{
|
|
314
333
|
const { format, pkgJson, autoExtension } = options;
|
|
315
334
|
let jsExtension = '.js';
|
|
@@ -1535,11 +1554,15 @@ async function createConstantRsbuildConfig() {
|
|
|
1535
1554
|
}
|
|
1536
1555
|
const composeFormatConfig = (format)=>{
|
|
1537
1556
|
const jsParserOptions = {
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1557
|
+
cjs: {
|
|
1558
|
+
requireResolve: false,
|
|
1559
|
+
requireDynamic: false,
|
|
1560
|
+
requireAsExpression: false
|
|
1561
|
+
},
|
|
1562
|
+
esm: {
|
|
1563
|
+
importMeta: false,
|
|
1564
|
+
importDynamic: false
|
|
1565
|
+
}
|
|
1543
1566
|
};
|
|
1544
1567
|
switch(format){
|
|
1545
1568
|
case 'esm':
|
|
@@ -1548,7 +1571,10 @@ const composeFormatConfig = (format)=>{
|
|
|
1548
1571
|
rspack: {
|
|
1549
1572
|
module: {
|
|
1550
1573
|
parser: {
|
|
1551
|
-
javascript:
|
|
1574
|
+
javascript: {
|
|
1575
|
+
...jsParserOptions.esm,
|
|
1576
|
+
...jsParserOptions.cjs
|
|
1577
|
+
}
|
|
1552
1578
|
}
|
|
1553
1579
|
},
|
|
1554
1580
|
optimization: {
|
|
@@ -1573,14 +1599,14 @@ const composeFormatConfig = (format)=>{
|
|
|
1573
1599
|
};
|
|
1574
1600
|
case 'cjs':
|
|
1575
1601
|
return {
|
|
1576
|
-
plugins: [
|
|
1577
|
-
pluginCjsShim()
|
|
1578
|
-
],
|
|
1579
1602
|
tools: {
|
|
1580
1603
|
rspack: {
|
|
1581
1604
|
module: {
|
|
1582
1605
|
parser: {
|
|
1583
|
-
javascript:
|
|
1606
|
+
javascript: {
|
|
1607
|
+
...jsParserOptions.esm,
|
|
1608
|
+
...jsParserOptions.cjs
|
|
1609
|
+
}
|
|
1584
1610
|
}
|
|
1585
1611
|
},
|
|
1586
1612
|
output: {
|
|
@@ -1619,6 +1645,45 @@ const composeFormatConfig = (format)=>{
|
|
|
1619
1645
|
throw new Error(`Unsupported format: ${format}`);
|
|
1620
1646
|
}
|
|
1621
1647
|
};
|
|
1648
|
+
const composeShimsConfig = (format, shims)=>{
|
|
1649
|
+
const resolvedShims = {
|
|
1650
|
+
cjs: {
|
|
1651
|
+
'import.meta.url': shims?.cjs?.['import.meta.url'] ?? true
|
|
1652
|
+
},
|
|
1653
|
+
esm: {
|
|
1654
|
+
__filename: shims?.esm?.__filename ?? false,
|
|
1655
|
+
__dirname: shims?.esm?.__dirname ?? false,
|
|
1656
|
+
require: shims?.esm?.require ?? false
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1659
|
+
switch(format){
|
|
1660
|
+
case 'esm':
|
|
1661
|
+
return {
|
|
1662
|
+
tools: {
|
|
1663
|
+
rspack: {
|
|
1664
|
+
node: {
|
|
1665
|
+
// "__dirname" and "__filename" shims will automatically be enabled when `output.module` is `true`
|
|
1666
|
+
__dirname: !!resolvedShims.esm.__dirname && 'node-module',
|
|
1667
|
+
__filename: !!resolvedShims.esm.__filename && 'node-module'
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
},
|
|
1671
|
+
plugins: [
|
|
1672
|
+
resolvedShims.esm.require && pluginEsmRequireShim()
|
|
1673
|
+
].filter(Boolean)
|
|
1674
|
+
};
|
|
1675
|
+
case 'cjs':
|
|
1676
|
+
return {
|
|
1677
|
+
plugins: [
|
|
1678
|
+
resolvedShims.cjs['import.meta.url'] && pluginCjsImportMetaUrlShim()
|
|
1679
|
+
].filter(Boolean)
|
|
1680
|
+
};
|
|
1681
|
+
case 'umd':
|
|
1682
|
+
return {};
|
|
1683
|
+
default:
|
|
1684
|
+
throw new Error(`Unsupported format: ${format}`);
|
|
1685
|
+
}
|
|
1686
|
+
};
|
|
1622
1687
|
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"')}.`;
|
|
1623
1688
|
const composeExternalsConfig = (format, externals)=>{
|
|
1624
1689
|
// TODO: Define the internal externals config in Rsbuild's externals instead
|
|
@@ -1883,7 +1948,8 @@ async function composeLibRsbuildConfig(config, configPath) {
|
|
|
1883
1948
|
const pkgJson = readPackageJson(rootPath);
|
|
1884
1949
|
const { compilerOptions } = await loadTsconfig(rootPath, config.source?.tsconfigPath);
|
|
1885
1950
|
const cssModulesAuto = config.output?.cssModules?.auto ?? true;
|
|
1886
|
-
const { format, banner = {}, footer = {}, autoExtension = true, autoExternal = true, externalHelpers = false, redirect = {} } = config;
|
|
1951
|
+
const { format, shims, banner = {}, footer = {}, autoExtension = true, autoExternal = true, externalHelpers = false, redirect = {} } = config;
|
|
1952
|
+
const shimsConfig = composeShimsConfig(format, shims);
|
|
1887
1953
|
const formatConfig = composeFormatConfig(format);
|
|
1888
1954
|
const externalHelpersConfig = composeExternalHelpersConfig(externalHelpers, pkgJson);
|
|
1889
1955
|
const externalsConfig = composeExternalsConfig(format, config.output?.externals);
|
|
@@ -1903,7 +1969,7 @@ async function composeLibRsbuildConfig(config, configPath) {
|
|
|
1903
1969
|
const minifyConfig = composeMinifyConfig(config.output?.minify);
|
|
1904
1970
|
const bannerFooterConfig = composeBannerFooterConfig(banner, footer);
|
|
1905
1971
|
const decoratorsConfig = composeDecoratorsConfig(compilerOptions, config.source?.decorators?.version);
|
|
1906
|
-
return (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(formatConfig, externalHelpersConfig, externalsWarnConfig, externalsConfig, autoExternalConfig, autoExtensionConfig, syntaxConfig, bundleConfig, targetConfig, entryConfig, cssConfig, minifyConfig, dtsConfig, bannerFooterConfig, decoratorsConfig);
|
|
1972
|
+
return (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.mergeRsbuildConfig)(formatConfig, shimsConfig, externalHelpersConfig, externalsWarnConfig, externalsConfig, autoExternalConfig, autoExtensionConfig, syntaxConfig, bundleConfig, targetConfig, entryConfig, cssConfig, minifyConfig, dtsConfig, bannerFooterConfig, decoratorsConfig);
|
|
1907
1973
|
}
|
|
1908
1974
|
async function composeCreateRsbuildConfig(rslibConfig, path) {
|
|
1909
1975
|
const constantRsbuildConfig = await createConstantRsbuildConfig();
|
|
@@ -1943,7 +2009,8 @@ async function composeCreateRsbuildConfig(rslibConfig, path) {
|
|
|
1943
2009
|
'externalHelpers',
|
|
1944
2010
|
'banner',
|
|
1945
2011
|
'footer',
|
|
1946
|
-
'dts'
|
|
2012
|
+
'dts',
|
|
2013
|
+
'shims'
|
|
1947
2014
|
]))
|
|
1948
2015
|
};
|
|
1949
2016
|
});
|
|
@@ -1984,7 +2051,7 @@ const applyCommonOptions = (command)=>{
|
|
|
1984
2051
|
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');
|
|
1985
2052
|
};
|
|
1986
2053
|
function runCli() {
|
|
1987
|
-
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.name('rslib').usage('<command> [options]').version("0.0.
|
|
2054
|
+
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.name('rslib').usage('<command> [options]').version("0.0.12");
|
|
1988
2055
|
const buildCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('build');
|
|
1989
2056
|
const inspectCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('inspect');
|
|
1990
2057
|
[
|
|
@@ -2026,6 +2093,6 @@ function runCli() {
|
|
|
2026
2093
|
});
|
|
2027
2094
|
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.parse();
|
|
2028
2095
|
}
|
|
2029
|
-
const src_version = "0.0.
|
|
2096
|
+
const src_version = "0.0.12";
|
|
2030
2097
|
var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger;
|
|
2031
2098
|
export { build, defineConfig, loadConfig, prepareCli, runCli, src_version as version, __webpack_exports__logger as logger };
|
|
@@ -19,6 +19,16 @@ export type BannerAndFooter = {
|
|
|
19
19
|
css?: string;
|
|
20
20
|
dts?: string;
|
|
21
21
|
};
|
|
22
|
+
export type Shims = {
|
|
23
|
+
cjs?: {
|
|
24
|
+
'import.meta.url'?: boolean;
|
|
25
|
+
};
|
|
26
|
+
esm?: {
|
|
27
|
+
__filename?: boolean;
|
|
28
|
+
__dirname?: boolean;
|
|
29
|
+
require?: boolean;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
22
32
|
export type Redirect = {
|
|
23
33
|
style?: boolean;
|
|
24
34
|
};
|
|
@@ -33,6 +43,7 @@ export interface LibConfig extends RsbuildConfig {
|
|
|
33
43
|
externalHelpers?: boolean;
|
|
34
44
|
banner?: BannerAndFooter;
|
|
35
45
|
footer?: BannerAndFooter;
|
|
46
|
+
shims?: Shims;
|
|
36
47
|
dts?: Dts;
|
|
37
48
|
}
|
|
38
49
|
export interface RslibConfig extends RsbuildConfig {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rslib/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "The Rspack-based library build tool.",
|
|
5
5
|
"homepage": "https://lib.rsbuild.dev",
|
|
6
6
|
"bugs": {
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"compiled"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@rsbuild/core": "1.0.
|
|
36
|
-
"rsbuild-plugin-dts": "0.0.
|
|
35
|
+
"@rsbuild/core": "~1.0.14",
|
|
36
|
+
"rsbuild-plugin-dts": "0.0.12"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@rspack/core": "1.0.8",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"commander": "^12.1.0",
|
|
42
42
|
"fast-glob": "^3.3.2",
|
|
43
43
|
"fs-extra": "^11.2.0",
|
|
44
|
-
"memfs": "^4.
|
|
44
|
+
"memfs": "^4.14.0",
|
|
45
45
|
"picocolors": "1.1.0",
|
|
46
46
|
"prebundle": "1.2.2",
|
|
47
|
-
"rslib": "npm:@rslib/core@0.0.
|
|
47
|
+
"rslib": "npm:@rslib/core@0.0.11",
|
|
48
48
|
"rslog": "^1.2.3",
|
|
49
49
|
"tsconfck": "3.1.4",
|
|
50
50
|
"typescript": "^5.6.3",
|