@rslib/core 0.1.4 → 0.2.0

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,11 +1,10 @@
1
1
  import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
2
- /**
3
- * The following code is modified based on
4
- * https://github.com/web-infra-dev/rspack/blob/0a89e433a9f8596a7c6c4326542f168b5982d2da/packages/rspack/src/builtin-plugin/css-extract/loader.ts
5
- * 1. remove hmr/webpack runtime
6
- * 2. add `this.emitFile` to emit css files
7
- * 3. add `import './[name].css';`
8
- */ const PLUGIN_NAME = 'LIB_CSS_EXTRACT_LOADER';
2
+ const BASE_URI = 'webpack://';
3
+ const MODULE_TYPE = 'css/mini-extract';
4
+ const AUTO_PUBLIC_PATH = '__mini_css_extract_plugin_public_path_auto__';
5
+ const ABSOLUTE_PUBLIC_PATH = `${BASE_URI}/mini-css-extract-plugin/`;
6
+ const SINGLE_DOT_PATH_SEGMENT = '__mini_css_extract_plugin_single_dot_path_segment__';
7
+ const LOADER_NAME = 'LIB_CSS_EXTRACT_LOADER';
9
8
  function stringifyLocal(value) {
10
9
  return 'function' == typeof value ? value.toString() : JSON.stringify(value);
11
10
  }
@@ -24,13 +23,21 @@ const pitch = function(request, _, _data) {
24
23
  const callback = this.async();
25
24
  const filepath = this.resourcePath;
26
25
  const rootDir = options.rootDir ?? this.rootContext;
26
+ let { publicPath } = this._compilation.outputOptions;
27
+ if ('string' == typeof options.publicPath) publicPath = options.publicPath;
28
+ else if ('function' == typeof options.publicPath) publicPath = options.publicPath(this.resourcePath, this.rootContext);
29
+ if ('auto' === publicPath) publicPath = AUTO_PUBLIC_PATH;
30
+ let publicPathForExtract;
31
+ if ('string' == typeof publicPath) {
32
+ const isAbsolutePublicPath = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(publicPath);
33
+ publicPathForExtract = isAbsolutePublicPath ? publicPath : `${ABSOLUTE_PUBLIC_PATH}${publicPath.replace(/\./g, SINGLE_DOT_PATH_SEGMENT)}`;
34
+ } else publicPathForExtract = publicPath;
27
35
  const handleExports = (originalExports)=>{
28
36
  let locals;
29
37
  let namedExport;
30
38
  const esModule = void 0 === options.esModule || options.esModule;
31
39
  let dependencies = [];
32
40
  try {
33
- // eslint-disable-next-line no-underscore-dangle
34
41
  const exports = originalExports.__esModule ? originalExports.default : originalExports;
35
42
  namedExport = originalExports.__esModule && (!originalExports.default || !('locals' in originalExports.default));
36
43
  if (namedExport) {
@@ -86,7 +93,7 @@ const pitch = function(request, _, _data) {
86
93
  if (esModule) return '\nexport {};';
87
94
  return '';
88
95
  }();
89
- let resultSource = `// extracted by ${PLUGIN_NAME}`;
96
+ let resultSource = `// extracted by ${LOADER_NAME}`;
90
97
  let importCssFiles = '';
91
98
  function getRelativePath(from, to) {
92
99
  let relativePath = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].relative(from, to);
@@ -112,7 +119,9 @@ const pitch = function(request, _, _data) {
112
119
  callback(null, resultSource, void 0);
113
120
  };
114
121
  this.importModule(`${this.resourcePath}.webpack[javascript/auto]!=!!!${request}`, {
115
- layer: options.layer
122
+ layer: options.layer,
123
+ publicPath: publicPathForExtract,
124
+ baseUri: `${BASE_URI}/`
116
125
  }, (error, exports)=>{
117
126
  if (error) {
118
127
  callback(error);
@@ -121,5 +130,5 @@ const pitch = function(request, _, _data) {
121
130
  handleExports(exports);
122
131
  });
123
132
  };
124
- /* ESM default export */ const libCssExtractLoader_rslib_entry_ = libCssExtractLoader_rslib_entry_loader;
125
- export { libCssExtractLoader_rslib_entry_ as default, pitch };
133
+ const libCssExtractLoader_rslib_entry_ = libCssExtractLoader_rslib_entry_loader;
134
+ export { ABSOLUTE_PUBLIC_PATH, AUTO_PUBLIC_PATH, BASE_URI, MODULE_TYPE, SINGLE_DOT_PATH_SEGMENT, libCssExtractLoader_rslib_entry_ as default, pitch };
@@ -0,0 +1,3 @@
1
+ import type { EnvironmentConfig } from '@rsbuild/core';
2
+ import type { Format } from '../types';
3
+ export declare const composeAssetConfig: (bundle: boolean, format: Format) => EnvironmentConfig;
@@ -1,4 +1,4 @@
1
1
  import { type RsbuildInstance } from '@rsbuild/core';
2
2
  import type { RslibConfig } from '../types/config';
3
3
  import type { BuildOptions } from './commands';
4
- export declare function build(config: RslibConfig, options?: Pick<BuildOptions, 'lib' | 'watch'>): Promise<RsbuildInstance>;
4
+ export declare function build(config: RslibConfig, options?: Pick<BuildOptions, 'lib' | 'watch' | 'root'>): Promise<RsbuildInstance>;
@@ -1,3 +1,4 @@
1
1
  import type { RsbuildInstance } from '@rsbuild/core';
2
2
  import type { RslibConfig } from '../types';
3
- export declare function startMFDevServer(config: RslibConfig): Promise<RsbuildInstance | undefined>;
3
+ import type { CommonOptions } from './commands';
4
+ export declare function startMFDevServer(config: RslibConfig, options?: Pick<CommonOptions, 'lib'>): Promise<RsbuildInstance | undefined>;
@@ -1,5 +1,5 @@
1
- import { type EnvironmentConfig, type RsbuildConfig } from '@rsbuild/core';
2
- import type { AutoExternal, BannerAndFooter, Format, LibConfig, PkgJson, RsbuildConfigEntry, RsbuildConfigWithLibInfo, RslibConfig, RslibConfigAsyncFn, RslibConfigExport, RslibConfigSyncFn } from './types';
1
+ import { type EnvironmentConfig } from '@rsbuild/core';
2
+ import type { AutoExternal, BannerAndFooter, Format, LibConfig, PkgJson, RequireKey, RsbuildConfigEntry, RsbuildConfigWithLibInfo, RslibConfig, RslibConfigAsyncFn, RslibConfigExport, RslibConfigSyncFn } from './types';
3
3
  /**
4
4
  * This function helps you to autocomplete configuration types.
5
5
  * It accepts a Rslib config object, or a function that returns a config.
@@ -20,14 +20,17 @@ export declare const composeAutoExternalConfig: (options: {
20
20
  format: Format;
21
21
  autoExternal?: AutoExternal;
22
22
  pkgJson?: PkgJson;
23
- userExternals?: NonNullable<RsbuildConfig["output"]>["externals"];
24
- }) => RsbuildConfig;
25
- export declare function composeMinifyConfig(config: LibConfig): RsbuildConfig;
26
- export declare function composeBannerFooterConfig(banner: BannerAndFooter, footer: BannerAndFooter): RsbuildConfig;
27
- export declare function composeDecoratorsConfig(compilerOptions?: Record<string, any>, version?: NonNullable<NonNullable<RsbuildConfig['source']>['decorators']>['version']): RsbuildConfig;
28
- export declare function createConstantRsbuildConfig(): Promise<RsbuildConfig>;
23
+ userExternals?: NonNullable<EnvironmentConfig["output"]>["externals"];
24
+ }) => EnvironmentConfig;
25
+ export declare function composeMinifyConfig(config: LibConfig): EnvironmentConfig;
26
+ export declare function composeBannerFooterConfig(banner: BannerAndFooter, footer: BannerAndFooter): EnvironmentConfig;
27
+ export declare function composeDecoratorsConfig(compilerOptions?: Record<string, any>, version?: NonNullable<NonNullable<EnvironmentConfig['source']>['decorators']>['version']): EnvironmentConfig;
28
+ export declare function createConstantRsbuildConfig(): Promise<EnvironmentConfig>;
29
29
  export declare const composeModuleImportWarn: (request: string) => string;
30
30
  export declare const appendEntryQuery: (entry: RsbuildConfigEntry) => RsbuildConfigEntry;
31
31
  export declare function composeCreateRsbuildConfig(rslibConfig: RslibConfig): Promise<RsbuildConfigWithLibInfo[]>;
32
- export declare function composeRsbuildEnvironments(rslibConfig: RslibConfig): Promise<Record<string, EnvironmentConfig>>;
32
+ export declare function composeRsbuildEnvironments(rslibConfig: RslibConfig): Promise<{
33
+ environments: Record<string, EnvironmentConfig>;
34
+ environmentWithInfos: RequireKey<RsbuildConfigWithLibInfo, 'id'>[];
35
+ }>;
33
36
  export declare const pruneEnvironments: (environments: Record<string, EnvironmentConfig>, libs?: string[]) => Record<string, EnvironmentConfig>;
@@ -0,0 +1,9 @@
1
+ import { type Rspack } from '@rsbuild/core';
2
+ type Options = Record<string, unknown>;
3
+ declare class LibCssExtractPlugin implements Rspack.RspackPluginInstance {
4
+ readonly name: string;
5
+ options: Options;
6
+ constructor(options?: Options);
7
+ apply(compiler: Rspack.Compiler): void;
8
+ }
9
+ export { LibCssExtractPlugin };
@@ -1,4 +1,4 @@
1
- import type { CSSLoaderOptions, RsbuildConfig } from '@rsbuild/core';
1
+ import type { CSSLoaderOptions, EnvironmentConfig } from '@rsbuild/core';
2
2
  export declare const RSLIB_CSS_ENTRY_FLAG = "__rslib_css__";
3
3
  export type CssLoaderOptionsAuto = CSSLoaderOptions['modules'] extends infer T ? T extends {
4
4
  auto?: any;
@@ -11,7 +11,7 @@ export declare function parsePathQueryFragment(str: string): {
11
11
  };
12
12
  export declare function isCssModulesFile(filepath: string, auto: CssLoaderOptionsAuto): boolean;
13
13
  export declare function isCssGlobalFile(filepath: string, auto: CssLoaderOptionsAuto): boolean;
14
- type ExternalCallback = (arg0?: null, arg1?: string) => void;
14
+ type ExternalCallback = (arg0?: undefined, arg1?: string) => void;
15
15
  export declare function cssExternalHandler(request: string, callback: ExternalCallback, jsExtension: string, auto: CssLoaderOptionsAuto, isStyleRedirect: boolean): void | false;
16
- export declare const composeCssConfig: (rootDir: string | null, bundle?: boolean) => RsbuildConfig;
16
+ export declare const composeCssConfig: (rootDir: string | null, bundle?: boolean) => EnvironmentConfig;
17
17
  export {};
@@ -1,5 +1,11 @@
1
1
  import type { Rspack } from '@rsbuild/core';
2
+ export declare const BASE_URI = "webpack://";
3
+ export declare const MODULE_TYPE = "css/mini-extract";
4
+ export declare const AUTO_PUBLIC_PATH = "__mini_css_extract_plugin_public_path_auto__";
5
+ export declare const ABSOLUTE_PUBLIC_PATH: string;
6
+ export declare const SINGLE_DOT_PATH_SEGMENT = "__mini_css_extract_plugin_single_dot_path_segment__";
2
7
  export interface CssExtractRspackLoaderOptions {
8
+ publicPath?: string | ((resourcePath: string, context: string) => string);
3
9
  emit?: boolean;
4
10
  esModule?: boolean;
5
11
  layer?: string;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This function is copied from
3
+ * https://github.com/webpack-contrib/mini-css-extract-plugin/blob/3effaa0319bad5cc1bf0ae760553bf7abcbc35a4/src/utils.js#L169
4
+ * linted by biome
5
+ */
6
+ declare function getUndoPath(filename: string, outputPathArg: string, enforceRelative: boolean): string;
7
+ export { getUndoPath };
@@ -0,0 +1 @@
1
+ {"//":"This file is for making TypeScript work with moduleResolution node16+.","version":"1.0.0"}
@@ -1,4 +1,4 @@
1
- import { type RsbuildConfig } from '@rsbuild/core';
1
+ import { type EnvironmentConfig } from '@rsbuild/core';
2
2
  export declare const composeEntryChunkConfig: ({ enabledImportMetaUrlShim, }: {
3
3
  enabledImportMetaUrlShim: boolean;
4
- }) => RsbuildConfig;
4
+ }) => EnvironmentConfig;
@@ -1,5 +1,6 @@
1
- import type { RsbuildConfig } from '@rsbuild/core';
1
+ import type { EnvironmentConfig, RsbuildConfig, Rspack } from '@rsbuild/core';
2
2
  import type { PluginDtsOptions } from 'rsbuild-plugin-dts';
3
+ import type { GetAsyncFunctionFromUnion } from './utils';
3
4
  export type Format = 'esm' | 'cjs' | 'umd' | 'mf';
4
5
  export type FixedEcmaVersions = 'es5' | 'es6' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'es2023';
5
6
  export type LatestEcmaVersions = 'es2024' | 'esnext';
@@ -7,11 +8,12 @@ export type EcmaScriptVersion = FixedEcmaVersions | LatestEcmaVersions;
7
8
  export type RsbuildConfigWithLibInfo = {
8
9
  id?: string;
9
10
  format: Format;
10
- config: RsbuildConfig;
11
+ config: EnvironmentConfig;
11
12
  };
12
- export type RsbuildConfigEntry = NonNullable<NonNullable<RsbuildConfig['source']>['entry']>;
13
+ export type RsbuildConfigEntry = NonNullable<NonNullable<EnvironmentConfig['source']>['entry']>;
13
14
  export type RsbuildConfigEntryItem = RsbuildConfigEntry[string];
14
- export type RsbuildConfigOutputTarget = NonNullable<RsbuildConfig['output']>['target'];
15
+ export type RspackResolver = GetAsyncFunctionFromUnion<ReturnType<NonNullable<Rspack.ExternalItemFunctionData['getResolve']>>>;
16
+ export type RsbuildConfigOutputTarget = NonNullable<EnvironmentConfig['output']>['target'];
15
17
  export type Syntax = EcmaScriptVersion | string[];
16
18
  export type Dts = (Pick<PluginDtsOptions, 'bundle' | 'distPath' | 'abortOnError' | 'build'> & {
17
19
  autoExtension?: boolean;
@@ -37,10 +39,25 @@ export type Shims = {
37
39
  require?: boolean;
38
40
  };
39
41
  };
42
+ export type JsRedirect = {
43
+ /**
44
+ * Whether to automatically redirect the import paths of JavaScript output files.
45
+ * @defaultValue `true`
46
+ */
47
+ path?: boolean;
48
+ /**
49
+ * Whether to automatically add the file extension to import paths based on the JavaScript output files.
50
+ * @defaultValue `true`
51
+ */
52
+ extension?: boolean;
53
+ };
40
54
  export type Redirect = {
55
+ /** Controls the redirect of the import paths of output JavaScript files. */
56
+ js?: JsRedirect;
57
+ /** Whether to redirect the import path of the style file. */
41
58
  style?: boolean;
42
59
  };
43
- export interface LibConfig extends RsbuildConfig {
60
+ export interface LibConfig extends EnvironmentConfig {
44
61
  /**
45
62
  * The unique identifier of the library.
46
63
  * @defaultValue `undefined`
@@ -133,7 +150,7 @@ export interface LibConfig extends RsbuildConfig {
133
150
  */
134
151
  umdName?: string;
135
152
  }
136
- export type LibOnlyConfig = Omit<LibConfig, keyof RsbuildConfig>;
153
+ export type LibOnlyConfig = Omit<LibConfig, keyof EnvironmentConfig>;
137
154
  export interface RslibConfig extends RsbuildConfig {
138
155
  lib: LibConfig[];
139
156
  }
@@ -9,4 +9,8 @@ export type PkgJson = {
9
9
  export type DeepRequired<T> = Required<{
10
10
  [K in keyof T]: T[K] extends Required<T[K]> ? T[K] : DeepRequired<T[K]>;
11
11
  }>;
12
+ export type RequireKey<T, K extends keyof T> = T & {
13
+ [P in K]-?: T[P];
14
+ };
12
15
  export type ExcludesFalse = <T>(x: T | false | undefined | null) => x is T;
16
+ export type GetAsyncFunctionFromUnion<T> = T extends (...args: any[]) => Promise<any> ? T : never;
@@ -22,3 +22,4 @@ export declare function debounce<T extends (...args: any[]) => void>(func: T, wa
22
22
  export declare const isTTY: (type?: "stdin" | "stdout") => boolean;
23
23
  export declare const isIntermediateOutputFormat: (format: Format) => boolean;
24
24
  export { color };
25
+ export declare function normalizeSlash(p: string): string;
@@ -1,4 +1,4 @@
1
- import type { RsbuildConfig, Rspack } from '@rsbuild/core';
1
+ import type { EnvironmentConfig, Rspack } from '@rsbuild/core';
2
2
  import type { FixedEcmaVersions, LatestEcmaVersions, RsbuildConfigOutputTarget, Syntax } from '../types/config';
3
3
  export declare const LATEST_TARGET_VERSIONS: Record<NonNullable<RsbuildConfigOutputTarget>, string[]>;
4
4
  /**
@@ -10,4 +10,4 @@ export declare const LATEST_TARGET_VERSIONS: Record<NonNullable<RsbuildConfigOut
10
10
  */
11
11
  export declare const ESX_TO_BROWSERSLIST: Record<FixedEcmaVersions, Record<string, string | string[]>> & Record<LatestEcmaVersions, (target: RsbuildConfigOutputTarget) => string[]>;
12
12
  export declare function transformSyntaxToRspackTarget(syntax: Syntax): Rspack.Configuration['target'];
13
- export declare function transformSyntaxToBrowserslist(syntax: Syntax, target: NonNullable<RsbuildConfig['output']>['target']): NonNullable<NonNullable<RsbuildConfig['output']>['overrideBrowserslist']>;
13
+ export declare function transformSyntaxToBrowserslist(syntax: Syntax, target: NonNullable<EnvironmentConfig['output']>['target']): NonNullable<NonNullable<EnvironmentConfig['output']>['overrideBrowserslist']>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rslib/core",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "The Rsbuild-based library development tool.",
5
5
  "homepage": "https://lib.rsbuild.dev",
6
6
  "bugs": {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/web-infra-dev/rslib",
11
+ "url": "git+https://github.com/web-infra-dev/rslib.git",
12
12
  "directory": "packages/core"
13
13
  },
14
14
  "license": "MIT",
@@ -32,19 +32,20 @@
32
32
  "compiled"
33
33
  ],
34
34
  "dependencies": {
35
- "@rsbuild/core": "~1.1.10",
35
+ "@rsbuild/core": "~1.1.12",
36
36
  "tinyglobby": "^0.2.10",
37
- "rsbuild-plugin-dts": "0.1.4"
37
+ "rsbuild-plugin-dts": "0.2.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/fs-extra": "^11.0.4",
41
- "chokidar": "^4.0.1",
41
+ "chokidar": "^4.0.3",
42
42
  "commander": "^12.1.0",
43
43
  "fs-extra": "^11.2.0",
44
- "memfs": "^4.15.0",
44
+ "memfs": "^4.15.1",
45
45
  "picocolors": "1.1.1",
46
46
  "prebundle": "1.2.5",
47
- "rslib": "npm:@rslib/core@0.1.3",
47
+ "rsbuild-plugin-publint": "^0.2.1",
48
+ "rslib": "npm:@rslib/core@0.1.5",
48
49
  "rslog": "^1.2.3",
49
50
  "tsconfck": "3.1.4",
50
51
  "typescript": "^5.6.3",
@@ -1,11 +0,0 @@
1
- import type { Rspack } from '@rsbuild/core';
2
- type Options = {
3
- include: RegExp;
4
- };
5
- declare class RemoveCssExtractAssetPlugin implements Rspack.RspackPluginInstance {
6
- readonly name: string;
7
- options: Options;
8
- constructor(options: Options);
9
- apply(compiler: Rspack.Compiler): void;
10
- }
11
- export { RemoveCssExtractAssetPlugin };