@rslib/core 0.3.2 → 0.4.1

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.
@@ -1,4 +1,4 @@
1
- import { Stats, Dirent, WatchEventType } from 'fs';
1
+ import { Dirent, Stats, WatchEventType } from 'fs';
2
2
  import { EventEmitter } from 'events';
3
3
  import { Readable } from 'stream';
4
4
 
@@ -617,7 +617,7 @@ declare class Command {
617
617
  * ```js
618
618
  * program
619
619
  * .option('-p, --pepper', 'add pepper')
620
- * .option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument
620
+ * .option('--pt, --pizza-type <TYPE>', 'type of pizza') // required option-argument
621
621
  * .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
622
622
  * .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
623
623
  * ```
@@ -41,10 +41,10 @@ module.exports = require("node:process");
41
41
 
42
42
  /***/ }),
43
43
 
44
- /***/ 710:
44
+ /***/ 277:
45
45
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
46
46
 
47
- const { InvalidArgumentError } = __nccwpck_require__(659);
47
+ const { InvalidArgumentError } = __nccwpck_require__(910);
48
48
 
49
49
  class Argument {
50
50
  /**
@@ -197,7 +197,7 @@ exports.humanReadableArgName = humanReadableArgName;
197
197
 
198
198
  /***/ }),
199
199
 
200
- /***/ 672:
200
+ /***/ 393:
201
201
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
202
202
 
203
203
  const EventEmitter = (__nccwpck_require__(474).EventEmitter);
@@ -206,11 +206,11 @@ const path = __nccwpck_require__(760);
206
206
  const fs = __nccwpck_require__(24);
207
207
  const process = __nccwpck_require__(708);
208
208
 
209
- const { Argument, humanReadableArgName } = __nccwpck_require__(710);
210
- const { CommanderError } = __nccwpck_require__(659);
211
- const { Help, stripColor } = __nccwpck_require__(254);
212
- const { Option, DualOptions } = __nccwpck_require__(388);
213
- const { suggestSimilar } = __nccwpck_require__(93);
209
+ const { Argument, humanReadableArgName } = __nccwpck_require__(277);
210
+ const { CommanderError } = __nccwpck_require__(910);
211
+ const { Help, stripColor } = __nccwpck_require__(945);
212
+ const { Option, DualOptions } = __nccwpck_require__(823);
213
+ const { suggestSimilar } = __nccwpck_require__(461);
214
214
 
215
215
  class Command extends EventEmitter {
216
216
  /**
@@ -958,7 +958,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
958
958
  * @example
959
959
  * program
960
960
  * .option('-p, --pepper', 'add pepper')
961
- * .option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument
961
+ * .option('--pt, --pizza-type <TYPE>', 'type of pizza') // required option-argument
962
962
  * .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
963
963
  * .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
964
964
  *
@@ -2866,7 +2866,7 @@ exports.useColor = useColor; // exporting for tests
2866
2866
 
2867
2867
  /***/ }),
2868
2868
 
2869
- /***/ 659:
2869
+ /***/ 910:
2870
2870
  /***/ ((__unused_webpack_module, exports) => {
2871
2871
 
2872
2872
  /**
@@ -2912,10 +2912,10 @@ exports.InvalidArgumentError = InvalidArgumentError;
2912
2912
 
2913
2913
  /***/ }),
2914
2914
 
2915
- /***/ 254:
2915
+ /***/ 945:
2916
2916
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
2917
2917
 
2918
- const { humanReadableArgName } = __nccwpck_require__(710);
2918
+ const { humanReadableArgName } = __nccwpck_require__(277);
2919
2919
 
2920
2920
  /**
2921
2921
  * TypeScript import types for JSDoc, used by Visual Studio Code IntelliSense and `npm run typescript-checkJS`
@@ -3628,10 +3628,10 @@ exports.stripColor = stripColor;
3628
3628
 
3629
3629
  /***/ }),
3630
3630
 
3631
- /***/ 388:
3631
+ /***/ 823:
3632
3632
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
3633
3633
 
3634
- const { InvalidArgumentError } = __nccwpck_require__(659);
3634
+ const { InvalidArgumentError } = __nccwpck_require__(910);
3635
3635
 
3636
3636
  class Option {
3637
3637
  /**
@@ -3651,7 +3651,7 @@ class Option {
3651
3651
  this.variadic = /\w\.\.\.[>\]]$/.test(flags); // The option can take multiple values.
3652
3652
  this.mandatory = false; // The option must have a value after parsing, which usually means it must be specified on command line.
3653
3653
  const optionFlags = splitOptionFlags(flags);
3654
- this.short = optionFlags.shortFlag;
3654
+ this.short = optionFlags.shortFlag; // May be a short flag, undefined, or even a long flag (if option has two long flags).
3655
3655
  this.long = optionFlags.longFlag;
3656
3656
  this.negate = false;
3657
3657
  if (this.long) {
@@ -3954,25 +3954,44 @@ function splitOptionFlags(flags) {
3954
3954
  const longFlagExp = /^--[^-]/;
3955
3955
 
3956
3956
  const flagParts = flags.split(/[ |,]+/).concat('guard');
3957
+ // Normal is short and/or long.
3957
3958
  if (shortFlagExp.test(flagParts[0])) shortFlag = flagParts.shift();
3958
3959
  if (longFlagExp.test(flagParts[0])) longFlag = flagParts.shift();
3960
+ // Long then short. Rarely used but fine.
3961
+ if (!shortFlag && shortFlagExp.test(flagParts[0]))
3962
+ shortFlag = flagParts.shift();
3963
+ // Allow two long flags, like '--ws, --workspace'
3964
+ // This is the supported way to have a shortish option flag.
3965
+ if (!shortFlag && longFlagExp.test(flagParts[0])) {
3966
+ shortFlag = longFlag;
3967
+ longFlag = flagParts.shift();
3968
+ }
3969
+
3970
+ // Check for unprocessed flag. Fail noisily rather than silently ignore.
3971
+ if (flagParts[0].startsWith('-')) {
3972
+ const unsupportedFlag = flagParts[0];
3973
+ const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
3974
+ if (/^-[^-][^-]/.test(unsupportedFlag))
3975
+ throw new Error(
3976
+ `${baseError}
3977
+ - a short flag is a single dash and a single character
3978
+ - either use a single dash and a single character (for a short flag)
3979
+ - or use a double dash for a long option (and can have two, like '--ws, --workspace')`,
3980
+ );
3981
+ if (shortFlagExp.test(unsupportedFlag))
3982
+ throw new Error(`${baseError}
3983
+ - too many short flags`);
3984
+ if (longFlagExp.test(unsupportedFlag))
3985
+ throw new Error(`${baseError}
3986
+ - too many long flags`);
3959
3987
 
3960
- // Check for some unsupported flags that people try.
3961
- if (/^-[^-][^-]/.test(flagParts[0]))
3962
- throw new Error(
3963
- `invalid Option flags, short option is dash and single character: '${flags}'`,
3964
- );
3965
- if (shortFlag && shortFlagExp.test(flagParts[0]))
3966
- throw new Error(
3967
- `invalid Option flags, more than one short flag: '${flags}'`,
3968
- );
3969
- if (longFlag && longFlagExp.test(flagParts[0]))
3988
+ throw new Error(`${baseError}
3989
+ - unrecognised flag format`);
3990
+ }
3991
+ if (shortFlag === undefined && longFlag === undefined)
3970
3992
  throw new Error(
3971
- `invalid Option flags, more than one long flag: '${flags}'`,
3993
+ `option creation failed due to no flags found in '${flags}'.`,
3972
3994
  );
3973
- // Generic error if failed to find a flag or an unexpected flag left over.
3974
- if (!(shortFlag || longFlag) || flagParts[0].startsWith('-'))
3975
- throw new Error(`invalid Option flags: '${flags}'`);
3976
3995
 
3977
3996
  return { shortFlag, longFlag };
3978
3997
  }
@@ -3983,7 +4002,7 @@ exports.DualOptions = DualOptions;
3983
4002
 
3984
4003
  /***/ }),
3985
4004
 
3986
- /***/ 93:
4005
+ /***/ 461:
3987
4006
  /***/ ((__unused_webpack_module, exports) => {
3988
4007
 
3989
4008
  const maxDistance = 3;
@@ -4133,11 +4152,11 @@ var __webpack_exports__ = {};
4133
4152
  // This entry need to be wrapped in an IIFE because it uses a non-standard name for the exports (exports).
4134
4153
  (() => {
4135
4154
  var exports = __webpack_exports__;
4136
- const { Argument } = __nccwpck_require__(710);
4137
- const { Command } = __nccwpck_require__(672);
4138
- const { CommanderError, InvalidArgumentError } = __nccwpck_require__(659);
4139
- const { Help } = __nccwpck_require__(254);
4140
- const { Option } = __nccwpck_require__(388);
4155
+ const { Argument } = __nccwpck_require__(277);
4156
+ const { Command } = __nccwpck_require__(393);
4157
+ const { CommanderError, InvalidArgumentError } = __nccwpck_require__(910);
4158
+ const { Help } = __nccwpck_require__(945);
4159
+ const { Option } = __nccwpck_require__(823);
4141
4160
 
4142
4161
  exports.program = new Command();
4143
4162
 
@@ -1 +1 @@
1
- {"name":"commander","author":"TJ Holowaychuk <tj@vision-media.ca>","version":"13.0.0","license":"MIT","types":"index.d.ts","type":"commonjs"}
1
+ {"name":"commander","author":"TJ Holowaychuk <tj@vision-media.ca>","version":"13.1.0","license":"MIT","types":"index.d.ts","type":"commonjs"}
@@ -1,6 +1,11 @@
1
1
  const RSLIB_ENTRY_QUERY = '__rslib_entry__';
2
2
  const SHEBANG_REGEX = /#!.*[\s\n\r]*$/;
3
3
  const REACT_DIRECTIVE_REGEX = /^['"]use (client|server)['"](;?)[\s\n\r]*$/;
4
+ const DTS_EXTENSIONS = [
5
+ 'd.ts',
6
+ 'd.mts',
7
+ 'd.cts'
8
+ ];
4
9
  const JS_EXTENSIONS = [
5
10
  'js',
6
11
  'mjs',
@@ -19,15 +24,13 @@ const CSS_EXTENSIONS = [
19
24
  'css',
20
25
  'sass',
21
26
  'scss',
22
- 'less'
23
- ];
24
- const ENTRY_EXTENSIONS = [
25
- ...JS_EXTENSIONS,
26
- ...CSS_EXTENSIONS
27
+ 'less',
28
+ 'styl',
29
+ 'stylus'
27
30
  ];
28
31
  new RegExp(`\\.(${JS_EXTENSIONS.join('|')})$`);
29
32
  new RegExp(`\\.(${CSS_EXTENSIONS.join('|')})$`);
30
- new RegExp(`\\.(${ENTRY_EXTENSIONS.join('|')})$`);
33
+ new RegExp(`\\.(${DTS_EXTENSIONS.join('|')})$`);
31
34
  function splitFromFirstLine(text) {
32
35
  const match = text.match(/(\r\n|\n)/);
33
36
  if (!match) return [
package/dist/index.js CHANGED
@@ -160,16 +160,8 @@ function prepareCli() {
160
160
  initNodeEnv();
161
161
  const { npm_execpath } = process.env;
162
162
  if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
163
- __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.greet(` Rslib v0.3.2\n`);
163
+ __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.greet(` Rslib v0.4.1\n`);
164
164
  }
165
- const composeAssetConfig = (bundle, format)=>{
166
- if ('esm' === format || 'cjs' === format) return {
167
- output: {
168
- dataUriLimit: 0
169
- }
170
- };
171
- return {};
172
- };
173
165
  const DEFAULT_CONFIG_NAME = 'rslib.config';
174
166
  const DEFAULT_CONFIG_EXTENSIONS = [
175
167
  '.js',
@@ -184,6 +176,11 @@ const RSLIB_ENTRY_QUERY = '__rslib_entry__';
184
176
  const SHEBANG_PREFIX = '#!';
185
177
  const SHEBANG_REGEX = /#!.*[\s\n\r]*$/;
186
178
  const REACT_DIRECTIVE_REGEX = /^['"]use (client|server)['"](;?)[\s\n\r]*$/;
179
+ const DTS_EXTENSIONS = [
180
+ 'd.ts',
181
+ 'd.mts',
182
+ 'd.cts'
183
+ ];
187
184
  const JS_EXTENSIONS = [
188
185
  'js',
189
186
  'mjs',
@@ -202,19 +199,13 @@ const CSS_EXTENSIONS = [
202
199
  'css',
203
200
  'sass',
204
201
  'scss',
205
- 'less'
206
- ];
207
- const ENTRY_EXTENSIONS = [
208
- ...JS_EXTENSIONS,
209
- ...CSS_EXTENSIONS
202
+ 'less',
203
+ 'styl',
204
+ 'stylus'
210
205
  ];
211
206
  const JS_EXTENSIONS_PATTERN = new RegExp(`\\.(${JS_EXTENSIONS.join('|')})$`);
212
207
  const CSS_EXTENSIONS_PATTERN = new RegExp(`\\.(${CSS_EXTENSIONS.join('|')})$`);
213
- const ENTRY_EXTENSIONS_PATTERN = new RegExp(`\\.(${ENTRY_EXTENSIONS.join('|')})$`);
214
- const BASE_URI = 'webpack://';
215
- const AUTO_PUBLIC_PATH = '__mini_css_extract_plugin_public_path_auto__';
216
- const ABSOLUTE_PUBLIC_PATH = `${BASE_URI}/mini-css-extract-plugin/`;
217
- const SINGLE_DOT_PATH_SEGMENT = '__mini_css_extract_plugin_single_dot_path_segment__';
208
+ const DTS_EXTENSIONS_PATTERN = new RegExp(`\\.(${DTS_EXTENSIONS.join('|')})$`);
218
209
  function getUndoPath(filename, outputPathArg, enforceRelative) {
219
210
  let depth = -1;
220
211
  let append = '';
@@ -232,6 +223,144 @@ function getUndoPath(filename, outputPathArg, enforceRelative) {
232
223
  } else if ('.' !== part) depth++;
233
224
  return depth > 0 ? `${'../'.repeat(depth)}${append}` : enforceRelative ? `./${append}` : append;
234
225
  }
226
+ const LibSvgrPatchPlugin_pluginName = 'LIB_SVGR_PATCH_PLUGIN';
227
+ const PUBLIC_PATH_PLACEHOLDER = '__RSLIB_SVGR_AUTO_PUBLIC_PATH__';
228
+ class LibSvgrPatchPlugin {
229
+ name = LibSvgrPatchPlugin_pluginName;
230
+ apply(compiler) {
231
+ compiler.hooks.make.tap(this.name, (compilation)=>{
232
+ compilation.hooks.processAssets.tap(this.name, (assets)=>{
233
+ const isEsm = Boolean(compilation.options.output.module);
234
+ const chunkAsset = Object.keys(assets).filter((name)=>/js$/.test(name));
235
+ for (const name of chunkAsset)compilation.updateAsset(name, (old)=>{
236
+ const oldSource = old.source().toString();
237
+ const newSource = new __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.rspack.sources.ReplaceSource(old);
238
+ const pattern = new RegExp(`\\(?['"]${PUBLIC_PATH_PLACEHOLDER}(.*)['"]\\)?`, 'g');
239
+ const matches = [
240
+ ...oldSource.matchAll(pattern)
241
+ ];
242
+ const len = matches.length;
243
+ if (0 === len) return old;
244
+ const undoPath = getUndoPath(name, compilation.outputOptions.path, true);
245
+ for(let i = 0; i < len; i++){
246
+ const match = matches[i];
247
+ const filename = match[1];
248
+ const requirePath = `${undoPath}${filename}`;
249
+ let replaced = '';
250
+ replaced = isEsm ? `__rslib_svgr_url__${i}__` : `require("${requirePath}")`;
251
+ newSource.replace(match.index, match.index + match[0].length - 1, replaced);
252
+ if (isEsm) newSource.insert(0, `import __rslib_svgr_url__${i}__ from "${requirePath}";\n`);
253
+ }
254
+ return newSource;
255
+ });
256
+ });
257
+ });
258
+ }
259
+ }
260
+ const PLUGIN_NAME = 'rsbuild:lib-asset';
261
+ const RSBUILD_SVGR_PLUGIN_NAME = 'rsbuild:svgr';
262
+ const pluginLibAsset = ({ bundle })=>({
263
+ name: PLUGIN_NAME,
264
+ pre: [
265
+ RSBUILD_SVGR_PLUGIN_NAME
266
+ ],
267
+ setup (api) {
268
+ api.modifyBundlerChain((config, { CHAIN_ID })=>{
269
+ const svgAssetRule = config.module.rules.get(CHAIN_ID.RULE.SVG).oneOfs.get(CHAIN_ID.ONE_OF.SVG_ASSET);
270
+ const originalTypeOptions = svgAssetRule.get('type');
271
+ const originalParserOptions = svgAssetRule.get('parser');
272
+ const originalGeneratorOptions = svgAssetRule.get('generator');
273
+ const isUserSetPublicPath = 'auto' !== config.output.get('publicPath');
274
+ const generatorOptions = isUserSetPublicPath ? originalGeneratorOptions : {
275
+ ...originalGeneratorOptions,
276
+ importMode: 'preserve'
277
+ };
278
+ const rule = config.module.rule(CHAIN_ID.RULE.SVG);
279
+ rule.oneOf(CHAIN_ID.ONE_OF.SVG_ASSET).generator(generatorOptions).issuer({
280
+ not: CSS_EXTENSIONS_PATTERN
281
+ });
282
+ rule.oneOf(`${CHAIN_ID.ONE_OF.SVG_ASSET}-for-css`).type(originalTypeOptions).parser(originalParserOptions).generator(originalGeneratorOptions).issuer(CSS_EXTENSIONS_PATTERN);
283
+ const ruleIds = [
284
+ CHAIN_ID.RULE.FONT,
285
+ CHAIN_ID.RULE.MEDIA,
286
+ CHAIN_ID.RULE.IMAGE,
287
+ CHAIN_ID.RULE.ADDITIONAL_ASSETS
288
+ ];
289
+ for (const ruleId of ruleIds){
290
+ const oneOfId = `${ruleId}-asset`;
291
+ const assetRule = config.module.rules.get(ruleId);
292
+ if (!assetRule) continue;
293
+ const assetRuleOneOf = assetRule.oneOfs.get(oneOfId);
294
+ const originalTypeOptions = assetRuleOneOf.get('type');
295
+ const originalParserOptions = assetRuleOneOf.get('parser');
296
+ const originalGeneratorOptions = assetRuleOneOf.get('generator');
297
+ const generatorOptions = isUserSetPublicPath ? originalGeneratorOptions : {
298
+ ...originalGeneratorOptions,
299
+ importMode: 'preserve'
300
+ };
301
+ const rule = config.module.rule(ruleId);
302
+ rule.oneOf(oneOfId).generator(generatorOptions).issuer({
303
+ not: CSS_EXTENSIONS_PATTERN
304
+ });
305
+ rule.oneOf(`${oneOfId}-for-css`).type(originalTypeOptions).parser(originalParserOptions).generator(originalGeneratorOptions).issuer(CSS_EXTENSIONS_PATTERN);
306
+ }
307
+ const isUsingSvgr = config.module.rule(CHAIN_ID.RULE.SVG).oneOf(CHAIN_ID.RULE.SVG).uses.has(CHAIN_ID.USE.SVGR);
308
+ const isUsingSvgrUrlLoader = config.module.rule(CHAIN_ID.RULE.SVG).oneOf(CHAIN_ID.ONE_OF.SVG).uses.has(CHAIN_ID.USE.URL);
309
+ if (isUsingSvgr && isUsingSvgrUrlLoader) {
310
+ const urlLoaderRule = config.module.rule(CHAIN_ID.RULE.SVG).oneOf(CHAIN_ID.ONE_OF.SVG).use(CHAIN_ID.USE.URL);
311
+ const originalOptions = urlLoaderRule.get('options');
312
+ urlLoaderRule.options({
313
+ ...originalOptions,
314
+ publicPath: (url)=>`${PUBLIC_PATH_PLACEHOLDER}${url}`
315
+ });
316
+ config.plugin(LibSvgrPatchPlugin.name).use(LibSvgrPatchPlugin, []);
317
+ }
318
+ if (!bundle) {
319
+ if (isUsingSvgr) {
320
+ const rule = config.module.rule(CHAIN_ID.RULE.SVG).oneOf(CHAIN_ID.ONE_OF.SVG);
321
+ rule.issuer([]);
322
+ }
323
+ }
324
+ if (bundle) config.plugins.get(CHAIN_ID.PLUGIN.MINI_CSS_EXTRACT)?.tap((options)=>[
325
+ {
326
+ ...options[0],
327
+ enforceRelative: true
328
+ }
329
+ ]);
330
+ });
331
+ }
332
+ });
333
+ const composeAssetConfig = (bundle, format)=>{
334
+ if ('esm' === format || 'cjs' === format) {
335
+ if (bundle) return {
336
+ output: {
337
+ dataUriLimit: 0,
338
+ assetPrefix: 'auto'
339
+ },
340
+ plugins: [
341
+ pluginLibAsset({
342
+ bundle: true
343
+ })
344
+ ]
345
+ };
346
+ return {
347
+ output: {
348
+ dataUriLimit: 0,
349
+ assetPrefix: 'auto'
350
+ },
351
+ plugins: [
352
+ pluginLibAsset({
353
+ bundle: false
354
+ })
355
+ ]
356
+ };
357
+ }
358
+ return {};
359
+ };
360
+ const BASE_URI = 'webpack://';
361
+ const AUTO_PUBLIC_PATH = '__mini_css_extract_plugin_public_path_auto__';
362
+ const ABSOLUTE_PUBLIC_PATH = `${BASE_URI}/mini-css-extract-plugin/`;
363
+ const SINGLE_DOT_PATH_SEGMENT = '__mini_css_extract_plugin_single_dot_path_segment__';
235
364
  const LibCssExtractPlugin_pluginName = 'LIB_CSS_EXTRACT_PLUGIN';
236
365
  class LibCssExtractPlugin {
237
366
  name = LibCssExtractPlugin_pluginName;
@@ -261,10 +390,11 @@ class LibCssExtractPlugin {
261
390
  start = oldSource.indexOf(searchValue, start + 1);
262
391
  }
263
392
  }
264
- replace(ABSOLUTE_PUBLIC_PATH, '');
265
393
  replace(SINGLE_DOT_PATH_SEGMENT, '.');
266
- const undoPath = getUndoPath(name, compilation.outputOptions.path, false);
267
- replace(AUTO_PUBLIC_PATH, undoPath);
394
+ const undoPath = getUndoPath(name, compilation.outputOptions.path, true);
395
+ replace(`${ABSOLUTE_PUBLIC_PATH}${AUTO_PUBLIC_PATH}`, undoPath);
396
+ replace(ABSOLUTE_PUBLIC_PATH, '');
397
+ replace(`${BASE_URI}/`, '');
268
398
  return replaceSource;
269
399
  });
270
400
  });
@@ -302,14 +432,17 @@ function isCssGlobalFile(filepath, auto) {
302
432
  const isCssModules = isCssModulesFile(filepath, auto);
303
433
  return !isCssModules;
304
434
  }
305
- async function cssExternalHandler(request, callback, jsExtension, auto, styleRedirectPath, styleRedirectExtension, redirectPath) {
435
+ async function cssExternalHandler(request, callback, jsExtension, auto, styleRedirectPath, styleRedirectExtension, redirectPath, issuer) {
306
436
  if (/compiled\/css-loader\//.test(request)) return callback();
307
437
  let resolvedRequest = request;
308
438
  if (styleRedirectPath) {
309
439
  const resolved = await redirectPath(resolvedRequest);
310
440
  if (resolved) resolvedRequest = resolved;
311
441
  }
312
- if (!isCssFile(resolvedRequest)) return false;
442
+ if (!isCssFile(resolvedRequest)) {
443
+ if (isCssFile(issuer)) return callback();
444
+ return false;
445
+ }
313
446
  if (styleRedirectExtension) {
314
447
  const isCssModulesRequest = isCssModulesFile(resolvedRequest, auto);
315
448
  if (isCssModulesRequest) return callback(void 0, resolvedRequest.replace(/\.[^.]+$/, jsExtension));
@@ -317,9 +450,9 @@ async function cssExternalHandler(request, callback, jsExtension, auto, styleRed
317
450
  }
318
451
  return callback(void 0, resolvedRequest);
319
452
  }
320
- const PLUGIN_NAME = 'rsbuild:lib-css';
321
- const pluginLibCss = (rootDir)=>({
322
- name: PLUGIN_NAME,
453
+ const cssConfig_PLUGIN_NAME = 'rsbuild:lib-css';
454
+ const pluginLibCss = (rootDir, banner, footer)=>({
455
+ name: cssConfig_PLUGIN_NAME,
323
456
  setup (api) {
324
457
  api.modifyBundlerChain((config, { CHAIN_ID })=>{
325
458
  let isUsingCssExtract = false;
@@ -333,7 +466,9 @@ const pluginLibCss = (rootDir)=>({
333
466
  if (rule.uses.has(CHAIN_ID.USE.MINI_CSS_EXTRACT)) {
334
467
  isUsingCssExtract = true;
335
468
  rule.use(CHAIN_ID.USE.MINI_CSS_EXTRACT).loader(cssConfig_require.resolve('./libCssExtractLoader.js')).options({
336
- rootDir
469
+ rootDir,
470
+ banner,
471
+ footer
337
472
  });
338
473
  }
339
474
  }
@@ -345,11 +480,11 @@ const pluginLibCss = (rootDir)=>({
345
480
  });
346
481
  }
347
482
  });
348
- const composeCssConfig = (rootDir, bundle = true)=>{
483
+ const composeCssConfig = (rootDir, bundle = true, banner, footer)=>{
349
484
  if (bundle || null === rootDir) return {};
350
485
  return {
351
486
  plugins: [
352
- pluginLibCss(rootDir)
487
+ pluginLibCss(rootDir, banner, footer)
353
488
  ],
354
489
  tools: {
355
490
  cssLoader: {
@@ -1829,7 +1964,7 @@ const composeEntryConfig = async (rawEntry, bundle, root, cssModulesAuto)=>{
1829
1964
  cwd: root,
1830
1965
  absolute: true
1831
1966
  });
1832
- const resolvedEntryFiles = globEntryFiles.filter((file)=>ENTRY_EXTENSIONS_PATTERN.test(file));
1967
+ const resolvedEntryFiles = globEntryFiles.filter((i)=>!DTS_EXTENSIONS_PATTERN.test(i));
1833
1968
  if (0 === resolvedEntryFiles.length) throw new Error(`Cannot find ${resolvedEntryFiles}`);
1834
1969
  const lcp = await calcLongestCommonPath(resolvedEntryFiles);
1835
1970
  const outBase = null === lcp ? root : lcp;
@@ -1841,7 +1976,7 @@ const composeEntryConfig = async (rawEntry, bundle, root, cssModulesAuto)=>{
1841
1976
  }
1842
1977
  for (const file of resolvedEntryFiles){
1843
1978
  const entryName = getEntryName(file);
1844
- if (resolvedEntries[entryName]) __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(`duplicate entry: ${entryName}, this may lead to the incorrect output, please rename the file`);
1979
+ if (resolvedEntries[entryName]) calcLcp && __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(`Duplicate entry ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__["default"].cyan(entryName)} from ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__["default"].cyan(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, file))} and ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__["default"].cyan(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, resolvedEntries[entryName]))}, which may lead to the incorrect output, please rename the file.`);
1845
1980
  resolvedEntries[entryName] = file;
1846
1981
  }
1847
1982
  }
@@ -1881,6 +2016,7 @@ const composeBundlelessExternalConfig = (jsExtension, redirect, cssModulesAuto,
1881
2016
  const styleRedirectExtension = redirect.style?.extension ?? true;
1882
2017
  const jsRedirectPath = redirect.js?.path ?? true;
1883
2018
  const jsRedirectExtension = redirect.js?.extension ?? true;
2019
+ const assetRedirect = redirect.asset ?? true;
1884
2020
  let resolver;
1885
2021
  return {
1886
2022
  resolvedJsRedirect: {
@@ -1913,19 +2049,20 @@ const composeBundlelessExternalConfig = (jsExtension, redirect, cssModulesAuto,
1913
2049
  }
1914
2050
  if (issuer) {
1915
2051
  let resolvedRequest = request;
1916
- const cssExternal = await cssExternalHandler(resolvedRequest, callback, jsExtension, cssModulesAuto, styleRedirectPath, styleRedirectExtension, redirectPath);
2052
+ const cssExternal = await cssExternalHandler(resolvedRequest, callback, jsExtension, cssModulesAuto, styleRedirectPath, styleRedirectExtension, redirectPath, issuer);
1917
2053
  if (false !== cssExternal) return cssExternal;
1918
2054
  if (jsRedirectPath) {
1919
2055
  const redirectedPath = await redirectPath(resolvedRequest);
1920
2056
  if (void 0 === redirectedPath) return callback(void 0, request);
1921
2057
  resolvedRequest = redirectedPath;
1922
2058
  }
1923
- if (jsRedirectExtension && resolvedRequest.startsWith('.')) {
2059
+ if (resolvedRequest.startsWith('.')) {
1924
2060
  const ext = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.extname)(resolvedRequest);
1925
2061
  if (ext) {
1926
- if (!JS_EXTENSIONS_PATTERN.test(resolvedRequest)) return callback();
1927
- resolvedRequest = resolvedRequest.replace(/\.[^.]+$/, jsExtension);
1928
- } else resolvedRequest = `${resolvedRequest}${jsExtension}`;
2062
+ if (JS_EXTENSIONS_PATTERN.test(resolvedRequest)) {
2063
+ if (jsRedirectExtension) resolvedRequest = resolvedRequest.replace(/\.[^.]+$/, jsExtension);
2064
+ } else if (assetRedirect) resolvedRequest = resolvedRequest.replace(/\.[^.]+$/, jsExtension);
2065
+ } else if (jsRedirectExtension) resolvedRequest = `${resolvedRequest}${jsExtension}`;
1929
2066
  }
1930
2067
  return callback(void 0, resolvedRequest);
1931
2068
  }
@@ -2057,7 +2194,7 @@ async function composeLibRsbuildConfig(config, root, sharedPlugins) {
2057
2194
  userExternals: config.output?.externals
2058
2195
  });
2059
2196
  const { entryConfig, lcp } = await composeEntryConfig(config.source?.entry, config.bundle, rootPath, cssModulesAuto);
2060
- const cssConfig = composeCssConfig(lcp, config.bundle);
2197
+ const cssConfig = composeCssConfig(lcp, config.bundle, banner?.css, footer?.css);
2061
2198
  const assetConfig = composeAssetConfig(bundle, format);
2062
2199
  const entryChunkConfig = composeEntryChunkConfig({
2063
2200
  enabledImportMetaUrlShim: enabledShims.cjs['import.meta.url'],
@@ -2283,7 +2420,7 @@ const repeatableOption = (value, previous)=>(previous ?? []).concat([
2283
2420
  value
2284
2421
  ]);
2285
2422
  function runCli() {
2286
- __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.name('rslib').usage('<command> [options]').version("0.3.2");
2423
+ __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.name('rslib').usage('<command> [options]').version("0.4.1");
2287
2424
  const buildCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.command('build');
2288
2425
  const inspectCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.command('inspect');
2289
2426
  const mfDevCommand = __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.command('mf-dev');
@@ -2344,6 +2481,6 @@ function runCli() {
2344
2481
  });
2345
2482
  __WEBPACK_EXTERNAL_MODULE__compiled_commander_index_js_bca3ceaa__.program.parse();
2346
2483
  }
2347
- const src_rslib_entry_version = "0.3.2";
2484
+ const src_rslib_entry_version = "0.4.1";
2348
2485
  var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger;
2349
2486
  export { build, defineConfig, inspect, loadConfig, prepareCli, runCli, startMFDevServer, composeCreateRsbuildConfig as unstable_composeCreateRsbuildConfig, src_rslib_entry_version as version, __webpack_exports__logger as logger };
@@ -23,6 +23,8 @@ const pitch = function(request, _, _data) {
23
23
  const callback = this.async();
24
24
  const filepath = this.resourcePath;
25
25
  const rootDir = options.rootDir ?? this.rootContext;
26
+ const banner = options.banner;
27
+ const footer = options.footer;
26
28
  let { publicPath } = this._compilation.outputOptions;
27
29
  if ('string' == typeof options.publicPath) publicPath = options.publicPath;
28
30
  else if ('function' == typeof options.publicPath) publicPath = options.publicPath(this.resourcePath, this.rootContext);
@@ -101,7 +103,7 @@ const pitch = function(request, _, _data) {
101
103
  return relativePath;
102
104
  }
103
105
  const m = new Map();
104
- for (const { content, filepath } of dependencies){
106
+ for (const { content, filepath, sourceMap } of dependencies){
105
107
  let distFilepath = getRelativePath(rootDir, filepath);
106
108
  const ext = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.extname)(distFilepath);
107
109
  if ('css' !== ext) distFilepath = distFilepath.replace(ext, '.css');
@@ -112,8 +114,18 @@ const pitch = function(request, _, _data) {
112
114
  importCssFiles += '\n';
113
115
  importCssFiles += `import "./${cssFilename}"`;
114
116
  }
117
+ if (sourceMap) {
118
+ const sourceMapPath = `${distFilepath}.map`;
119
+ m.set(sourceMapPath, `${sourceMap}`);
120
+ const sourceMappingURL = `/*# sourceMappingURL=${cssFilename}.map */`;
121
+ m.set(distFilepath, `${m.get(distFilepath)}\n${sourceMappingURL}`);
122
+ }
123
+ }
124
+ for (let [distFilepath, content] of m.entries()){
125
+ if (banner) content = `${banner}\n${content}`;
126
+ if (footer) content = `${content}\n${footer}\n`;
127
+ this.emitFile(distFilepath, content);
115
128
  }
116
- for (const [distFilepath, content] of m.entries())this.emitFile(distFilepath, content);
117
129
  resultSource += importCssFiles;
118
130
  resultSource += result;
119
131
  callback(null, resultSource, void 0);
@@ -0,0 +1,6 @@
1
+ import { type Rspack } from '@rsbuild/core';
2
+ export declare const PUBLIC_PATH_PLACEHOLDER = "__RSLIB_SVGR_AUTO_PUBLIC_PATH__";
3
+ export declare class LibSvgrPatchPlugin implements Rspack.RspackPluginInstance {
4
+ readonly name: string;
5
+ apply(compiler: Rspack.Compiler): void;
6
+ }
@@ -7,4 +7,4 @@ export declare const SHEBANG_REGEX: RegExp;
7
7
  export declare const REACT_DIRECTIVE_REGEX: RegExp;
8
8
  export declare const JS_EXTENSIONS_PATTERN: RegExp;
9
9
  export declare const CSS_EXTENSIONS_PATTERN: RegExp;
10
- export declare const ENTRY_EXTENSIONS_PATTERN: RegExp;
10
+ export declare const DTS_EXTENSIONS_PATTERN: RegExp;
@@ -12,6 +12,6 @@ export declare function parsePathQueryFragment(str: string): {
12
12
  export declare function isCssModulesFile(filepath: string, auto: CssLoaderOptionsAuto): boolean;
13
13
  export declare function isCssGlobalFile(filepath: string, auto: CssLoaderOptionsAuto): boolean;
14
14
  type ExternalCallback = (arg0?: undefined, arg1?: string) => void;
15
- export declare function cssExternalHandler(request: string, callback: ExternalCallback, jsExtension: string, auto: CssLoaderOptionsAuto, styleRedirectPath: boolean, styleRedirectExtension: boolean, redirectPath: (request: string) => Promise<string | undefined>): Promise<false | void>;
16
- export declare const composeCssConfig: (rootDir: string | null, bundle?: boolean) => EnvironmentConfig;
15
+ export declare function cssExternalHandler(request: string, callback: ExternalCallback, jsExtension: string, auto: CssLoaderOptionsAuto, styleRedirectPath: boolean, styleRedirectExtension: boolean, redirectPath: (request: string) => Promise<string | undefined>, issuer: string): Promise<false | void>;
16
+ export declare const composeCssConfig: (rootDir: string | null, bundle?: boolean, banner?: string, footer?: string) => EnvironmentConfig;
17
17
  export {};
@@ -11,6 +11,8 @@ export interface CssExtractRspackLoaderOptions {
11
11
  layer?: string;
12
12
  defaultExport?: boolean;
13
13
  rootDir?: string;
14
+ banner?: string;
15
+ footer?: string;
14
16
  }
15
17
  declare const loader: Rspack.LoaderDefinition;
16
18
  export declare const pitch: Rspack.LoaderDefinition['pitch'];
@@ -144,6 +144,8 @@ export type Redirect = {
144
144
  js?: JsRedirect;
145
145
  /** Controls the redirect of the import paths of output style files. */
146
146
  style?: StyleRedirect;
147
+ /** Controls the redirect of the import paths of output asset files. */
148
+ asset?: boolean;
147
149
  };
148
150
  export interface LibConfig extends EnvironmentConfig {
149
151
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rslib/core",
3
- "version": "0.3.2",
3
+ "version": "0.4.1",
4
4
  "description": "The Rsbuild-based library development tool.",
5
5
  "homepage": "https://lib.rsbuild.dev",
6
6
  "bugs": {
@@ -18,6 +18,9 @@
18
18
  "types": "./dist-types/index.d.ts",
19
19
  "default": "./dist/index.js"
20
20
  },
21
+ "./types": {
22
+ "types": "./types.d.ts"
23
+ },
21
24
  "./package.json": "./package.json"
22
25
  },
23
26
  "main": "./dist/index.js",
@@ -29,24 +32,25 @@
29
32
  "bin",
30
33
  "dist",
31
34
  "dist-types",
32
- "compiled"
35
+ "compiled",
36
+ "types.d.ts"
33
37
  ],
34
38
  "dependencies": {
35
- "@rsbuild/core": "1.2.0-beta.1",
39
+ "@rsbuild/core": "~1.2.4",
36
40
  "tinyglobby": "^0.2.10",
37
- "rsbuild-plugin-dts": "0.3.2"
41
+ "rsbuild-plugin-dts": "0.4.1"
38
42
  },
39
43
  "devDependencies": {
40
44
  "@module-federation/rsbuild-plugin": "^0.8.9",
41
45
  "@types/fs-extra": "^11.0.4",
42
46
  "chokidar": "^4.0.3",
43
- "commander": "^13.0.0",
47
+ "commander": "^13.1.0",
44
48
  "fs-extra": "^11.3.0",
45
49
  "memfs": "^4.17.0",
46
50
  "picocolors": "1.1.1",
47
51
  "prebundle": "1.2.7",
48
- "rsbuild-plugin-publint": "^0.2.1",
49
- "rslib": "npm:@rslib/core@0.3.1",
52
+ "rsbuild-plugin-publint": "^0.3.0",
53
+ "rslib": "npm:@rslib/core@0.4.0",
50
54
  "rslog": "^1.2.3",
51
55
  "tsconfck": "3.1.4",
52
56
  "typescript": "^5.7.3",
package/types.d.ts ADDED
@@ -0,0 +1 @@
1
+ /// <reference types="@rsbuild/core/types" />