@modern-js/module-tools 2.46.1 → 2.47.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,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { ICompiler } from '../../types';
2
+ import type { ICompiler } from '../../types';
3
3
  export declare const asset: {
4
4
  name: string;
5
5
  apply(compiler: ICompiler): void;
@@ -14,5 +14,5 @@ export declare const asset: {
14
14
  */
15
15
  export declare function getAssetContents(this: ICompiler, assetPath: string, rebaseFrom: string, calledOnLoad?: boolean): Promise<{
16
16
  contents: string | Buffer;
17
- loader: "copy" | "text" | "jsx";
17
+ loader: "text" | "jsx" | "copy";
18
18
  }>;
@@ -34,6 +34,7 @@ __export(asset_exports, {
34
34
  module.exports = __toCommonJS(asset_exports);
35
35
  var import_path = require("path");
36
36
  var import_fs = __toESM(require("fs"));
37
+ var import_lodash = __toESM(require("@modern-js/utils/lodash"));
37
38
  var import_pluginutils = require("@rollup/pluginutils");
38
39
  var import_core = require("../../../compiled/@svgr/core");
39
40
  var import_plugin_svgo = __toESM(require("../../../compiled/@svgr/plugin-svgo"));
@@ -67,6 +68,24 @@ const asset = {
67
68
  function encodeSVG(buffer) {
68
69
  return encodeURIComponent(buffer.toString("utf-8").replace(/[\n\r]/gim, "").replace(/\t/gim, " ").replace(/<!--(.*(?=-->))-->/gim, "").replace(/'/gim, "\\i")).replace(/\(/g, "%28").replace(/\)/g, "%29");
69
70
  }
71
+ const getDefaultSVGRConfig = () => ({
72
+ svgo: true,
73
+ svgoConfig: {
74
+ plugins: [
75
+ {
76
+ name: "preset-default",
77
+ params: {
78
+ overrides: {
79
+ // viewBox is required to resize SVGs with CSS.
80
+ // @see https://github.com/svg/svgo/issues/1128
81
+ removeViewBox: false
82
+ }
83
+ }
84
+ },
85
+ "prefixIds"
86
+ ]
87
+ }
88
+ });
70
89
  async function getAssetContents(assetPath, rebaseFrom, calledOnLoad) {
71
90
  const fileContent = await import_fs.default.promises.readFile(assetPath);
72
91
  const { buildType, format, outDir } = this.config;
@@ -80,7 +99,8 @@ async function getAssetContents(assetPath, rebaseFrom, calledOnLoad) {
80
99
  let emitAsset = true;
81
100
  let contents = normalizedPublicPath;
82
101
  let loader = "text";
83
- const config = typeof svgr === "boolean" ? {} : svgr;
102
+ const defaultConfig = getDefaultSVGRConfig();
103
+ const config = typeof svgr === "boolean" ? defaultConfig : import_lodash.default.merge(defaultConfig, svgr);
84
104
  const filter = (0, import_pluginutils.createFilter)(config.include || SVG_REGEXP, config.exclude);
85
105
  if (svgr && filter(assetPath)) {
86
106
  const previousExport = config.exportType === "named" ? `export default "${normalizedPublicPath}"` : null;
@@ -40,7 +40,7 @@ var import_file = require("../../constants/file");
40
40
  var import_utils2 = require("../../utils");
41
41
  var import_asset = require("./asset");
42
42
  var import_postcssTransformer = require("./style/postcssTransformer");
43
- async function redirectImport(compiler, code, modules, aliasRecord, filePath, outputDir, jsExtension, matchPath) {
43
+ async function redirectImport(compiler, code, modules, aliasRecord, filePath, outputDir, jsExtension, isModule, matchPath) {
44
44
  const str = new import_magic_string.default(code);
45
45
  const extensions = [
46
46
  ".ts",
@@ -77,7 +77,7 @@ async function redirectImport(compiler, code, modules, aliasRecord, filePath, ou
77
77
  }
78
78
  }
79
79
  if (redirect2.autoExtension) {
80
- if (ext === "" && jsExtension !== ".js" && name2.startsWith(".")) {
80
+ if (ext === "" && name2.startsWith(".") && (jsExtension !== ".js" || isModule)) {
81
81
  str.overwrite(start, end, `${name2}${jsExtension}`);
82
82
  return;
83
83
  }
@@ -214,13 +214,13 @@ const redirect = {
214
214
  if (!matchModule.length) {
215
215
  return args;
216
216
  }
217
- const { jsExtension } = (0, import_utils2.getDefaultOutExtension)({
217
+ const { jsExtension, isModule } = (0, import_utils2.getDefaultOutExtension)({
218
218
  format,
219
219
  root,
220
220
  autoExtension
221
221
  });
222
222
  const outputPath = (0, import_path.resolve)(outDir, (0, import_path.relative)(sourceDir, id));
223
- const str = await redirectImport(compiler, code, matchModule, absoluteAlias, id, (0, import_path.dirname)(outputPath), jsExtension, matchPath);
223
+ const str = await redirectImport(compiler, code, matchModule, absoluteAlias, id, (0, import_path.dirname)(outputPath), jsExtension, isModule, matchPath);
224
224
  return {
225
225
  ...args,
226
226
  code: str.toString(),
@@ -9,5 +9,5 @@ export type PreprocessRender = (content: string, stdinPath: string, stdinDir: st
9
9
  }>;
10
10
  export declare function transformStyle(this: ICompiler, source: Source): Promise<{
11
11
  code: string;
12
- loader: "js" | "css";
12
+ loader: "css" | "js";
13
13
  }>;
@@ -1,7 +1,7 @@
1
- import type { ToolsConfig as WebpackBuilderToolsConfig } from '@modern-js/builder-webpack-provider';
1
+ import type { ToolsConfig } from '@rsbuild/core';
2
2
  export interface StorybookBuildConfig {
3
- webpack?: WebpackBuilderToolsConfig['webpack'];
4
- webpackChain?: WebpackBuilderToolsConfig['webpackChain'];
3
+ webpack?: ToolsConfig['webpack'];
4
+ webpackChain?: ToolsConfig['webpackChain'];
5
5
  }
6
6
  export interface Dev {
7
7
  storybook?: StorybookBuildConfig;
@@ -6,4 +6,9 @@ export declare const getDefaultOutExtension: (options: {
6
6
  }) => {
7
7
  jsExtension: string;
8
8
  dtsExtension: string;
9
+ isModule?: undefined;
10
+ } | {
11
+ jsExtension: string;
12
+ dtsExtension: string;
13
+ isModule: boolean;
9
14
  };
@@ -64,7 +64,8 @@ const getDefaultOutExtension = (options) => {
64
64
  }
65
65
  return {
66
66
  jsExtension,
67
- dtsExtension
67
+ dtsExtension,
68
+ isModule
68
69
  };
69
70
  };
70
71
  // Annotate the CommonJS export names for ESM import in node:
package/lib/types.d.ts CHANGED
@@ -34,8 +34,18 @@ declare module '*.webp' {
34
34
  }
35
35
 
36
36
  declare module '*.svg' {
37
- const src: string;
38
- export default src;
37
+ import * as React from 'react';
38
+
39
+ export const ReactComponent: React.FunctionComponent<
40
+ React.SVGProps<SVGSVGElement>
41
+ >;
42
+
43
+ /**
44
+ * The default export type depends on the asset.svgr.exportType config,
45
+ * it can be a string or a ReactComponent
46
+ * */
47
+ const content: any;
48
+ export default content;
39
49
  }
40
50
 
41
51
  declare module '*.css' {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/module-tools",
3
- "version": "2.46.1",
3
+ "version": "2.47.1",
4
4
  "description": "Simple, powerful, high-performance modern npm package development solution.",
5
5
  "keywords": [
6
6
  "modern",
@@ -66,24 +66,24 @@
66
66
  "tapable": "2.2.1",
67
67
  "terser": "5.19.2",
68
68
  "tsconfig-paths-webpack-plugin": "4.1.0",
69
- "@modern-js/core": "2.46.1",
70
- "@modern-js/new-action": "2.46.1",
71
- "@modern-js/plugin-changeset": "2.46.1",
72
- "@modern-js/plugin": "2.46.1",
73
- "@modern-js/plugin-i18n": "2.46.1",
74
- "@modern-js/plugin-lint": "2.46.1",
75
- "@modern-js/types": "2.46.1",
76
- "@modern-js/upgrade": "2.46.1",
77
- "@modern-js/utils": "2.46.1"
69
+ "@modern-js/core": "2.47.1",
70
+ "@modern-js/new-action": "2.47.1",
71
+ "@modern-js/plugin": "2.47.1",
72
+ "@modern-js/plugin-changeset": "2.47.1",
73
+ "@modern-js/plugin-i18n": "2.47.1",
74
+ "@modern-js/types": "2.47.1",
75
+ "@modern-js/plugin-lint": "2.47.1",
76
+ "@modern-js/upgrade": "2.47.1",
77
+ "@modern-js/utils": "2.47.1"
78
78
  },
79
79
  "devDependencies": {
80
+ "@rsbuild/core": "0.4.6",
80
81
  "@types/convert-source-map": "1.5.2",
81
82
  "@types/node": "^14",
82
83
  "typescript": "^5",
83
- "@modern-js/builder-webpack-provider": "2.46.1",
84
- "@modern-js/self": "npm:@modern-js/module-tools@2.46.1",
85
- "@scripts/vitest-config": "2.46.1",
86
- "@scripts/build": "2.46.1"
84
+ "@modern-js/self": "npm:@modern-js/module-tools@2.47.1",
85
+ "@scripts/build": "2.47.1",
86
+ "@scripts/vitest-config": "2.47.1"
87
87
  },
88
88
  "peerDependencies": {
89
89
  "typescript": "^4 || ^5"