@rslib/core 0.0.10 → 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 = [
|
|
@@ -289,34 +289,41 @@ const composeCssConfig = (rootDir, bundle = true)=>{
|
|
|
289
289
|
}
|
|
290
290
|
};
|
|
291
291
|
};
|
|
292
|
-
const importMetaUrlShim =
|
|
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
|
-
})()
|
|
298
|
-
`;
|
|
297
|
+
})()`;
|
|
299
298
|
// This Rsbuild plugin will shim `import.meta.url` for CommonJS modules.
|
|
300
299
|
// - Replace `import.meta.url` with `importMetaUrl`.
|
|
301
300
|
// - Inject `importMetaUrl` to the end of the module (can't inject at the beginning because of `"use strict";`).
|
|
302
301
|
// This is a short-term solution, and we hope to provide built-in polyfills like `node.__filename` on Rspack side.
|
|
303
|
-
const
|
|
304
|
-
name: 'rsbuild-
|
|
302
|
+
const pluginCjsImportMetaUrlShim = ()=>({
|
|
303
|
+
name: 'rsbuild:cjs-import-meta-url-shim',
|
|
305
304
|
setup (api) {
|
|
306
305
|
api.modifyEnvironmentConfig((config)=>{
|
|
307
306
|
config.source.define = {
|
|
308
307
|
...config.source.define,
|
|
309
|
-
'import.meta.url':
|
|
308
|
+
'import.meta.url': importMetaUrlShim
|
|
310
309
|
};
|
|
311
310
|
});
|
|
311
|
+
}
|
|
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) {
|
|
312
320
|
api.modifyRspackConfig((config)=>{
|
|
313
321
|
config.plugins ??= [];
|
|
314
322
|
config.plugins.push(new __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.BannerPlugin({
|
|
315
|
-
banner:
|
|
323
|
+
banner: requireShim,
|
|
316
324
|
// Just before minify stage, to perform tree shaking.
|
|
317
325
|
stage: __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE - 1,
|
|
318
326
|
raw: true,
|
|
319
|
-
footer: true,
|
|
320
327
|
include: /\.(js|cjs)$/
|
|
321
328
|
}));
|
|
322
329
|
});
|
|
@@ -1547,11 +1554,15 @@ async function createConstantRsbuildConfig() {
|
|
|
1547
1554
|
}
|
|
1548
1555
|
const composeFormatConfig = (format)=>{
|
|
1549
1556
|
const jsParserOptions = {
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1557
|
+
cjs: {
|
|
1558
|
+
requireResolve: false,
|
|
1559
|
+
requireDynamic: false,
|
|
1560
|
+
requireAsExpression: false
|
|
1561
|
+
},
|
|
1562
|
+
esm: {
|
|
1563
|
+
importMeta: false,
|
|
1564
|
+
importDynamic: false
|
|
1565
|
+
}
|
|
1555
1566
|
};
|
|
1556
1567
|
switch(format){
|
|
1557
1568
|
case 'esm':
|
|
@@ -1560,7 +1571,10 @@ const composeFormatConfig = (format)=>{
|
|
|
1560
1571
|
rspack: {
|
|
1561
1572
|
module: {
|
|
1562
1573
|
parser: {
|
|
1563
|
-
javascript:
|
|
1574
|
+
javascript: {
|
|
1575
|
+
...jsParserOptions.esm,
|
|
1576
|
+
...jsParserOptions.cjs
|
|
1577
|
+
}
|
|
1564
1578
|
}
|
|
1565
1579
|
},
|
|
1566
1580
|
optimization: {
|
|
@@ -1585,14 +1599,14 @@ const composeFormatConfig = (format)=>{
|
|
|
1585
1599
|
};
|
|
1586
1600
|
case 'cjs':
|
|
1587
1601
|
return {
|
|
1588
|
-
plugins: [
|
|
1589
|
-
pluginCjsShim()
|
|
1590
|
-
],
|
|
1591
1602
|
tools: {
|
|
1592
1603
|
rspack: {
|
|
1593
1604
|
module: {
|
|
1594
1605
|
parser: {
|
|
1595
|
-
javascript:
|
|
1606
|
+
javascript: {
|
|
1607
|
+
...jsParserOptions.esm,
|
|
1608
|
+
...jsParserOptions.cjs
|
|
1609
|
+
}
|
|
1596
1610
|
}
|
|
1597
1611
|
},
|
|
1598
1612
|
output: {
|
|
@@ -1631,6 +1645,45 @@ const composeFormatConfig = (format)=>{
|
|
|
1631
1645
|
throw new Error(`Unsupported format: ${format}`);
|
|
1632
1646
|
}
|
|
1633
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
|
+
};
|
|
1634
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"')}.`;
|
|
1635
1688
|
const composeExternalsConfig = (format, externals)=>{
|
|
1636
1689
|
// TODO: Define the internal externals config in Rsbuild's externals instead
|
|
@@ -1895,7 +1948,8 @@ async function composeLibRsbuildConfig(config, configPath) {
|
|
|
1895
1948
|
const pkgJson = readPackageJson(rootPath);
|
|
1896
1949
|
const { compilerOptions } = await loadTsconfig(rootPath, config.source?.tsconfigPath);
|
|
1897
1950
|
const cssModulesAuto = config.output?.cssModules?.auto ?? true;
|
|
1898
|
-
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);
|
|
1899
1953
|
const formatConfig = composeFormatConfig(format);
|
|
1900
1954
|
const externalHelpersConfig = composeExternalHelpersConfig(externalHelpers, pkgJson);
|
|
1901
1955
|
const externalsConfig = composeExternalsConfig(format, config.output?.externals);
|
|
@@ -1915,7 +1969,7 @@ async function composeLibRsbuildConfig(config, configPath) {
|
|
|
1915
1969
|
const minifyConfig = composeMinifyConfig(config.output?.minify);
|
|
1916
1970
|
const bannerFooterConfig = composeBannerFooterConfig(banner, footer);
|
|
1917
1971
|
const decoratorsConfig = composeDecoratorsConfig(compilerOptions, config.source?.decorators?.version);
|
|
1918
|
-
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);
|
|
1919
1973
|
}
|
|
1920
1974
|
async function composeCreateRsbuildConfig(rslibConfig, path) {
|
|
1921
1975
|
const constantRsbuildConfig = await createConstantRsbuildConfig();
|
|
@@ -1955,7 +2009,8 @@ async function composeCreateRsbuildConfig(rslibConfig, path) {
|
|
|
1955
2009
|
'externalHelpers',
|
|
1956
2010
|
'banner',
|
|
1957
2011
|
'footer',
|
|
1958
|
-
'dts'
|
|
2012
|
+
'dts',
|
|
2013
|
+
'shims'
|
|
1959
2014
|
]))
|
|
1960
2015
|
};
|
|
1961
2016
|
});
|
|
@@ -1996,7 +2051,7 @@ const applyCommonOptions = (command)=>{
|
|
|
1996
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');
|
|
1997
2052
|
};
|
|
1998
2053
|
function runCli() {
|
|
1999
|
-
__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");
|
|
2000
2055
|
const buildCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('build');
|
|
2001
2056
|
const inspectCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.command('inspect');
|
|
2002
2057
|
[
|
|
@@ -2038,6 +2093,6 @@ function runCli() {
|
|
|
2038
2093
|
});
|
|
2039
2094
|
__WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js__.program.parse();
|
|
2040
2095
|
}
|
|
2041
|
-
const src_version = "0.0.
|
|
2096
|
+
const src_version = "0.0.12";
|
|
2042
2097
|
var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js__.logger;
|
|
2043
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",
|