@modern-js/utils 1.21.5 → 2.0.0-beta.1

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,10 +1,90 @@
1
1
  # @modern-js/utils
2
2
 
3
- ## 1.21.5
3
+ ## 2.0.0-beta.1
4
4
 
5
- ## 1.21.4
5
+ ### Major Changes
6
6
 
7
- ## 1.21.3
7
+ - dda38c9: chore: v2
8
+
9
+ ### Minor Changes
10
+
11
+ - 92f0ead: feat:
12
+
13
+ 1. core: 增加 test 函数
14
+ 2. module plugins: 增加 `babel`, `mainField`, `target` 插件
15
+ 3. storybook: 修改部分逻辑并且增加 tspath webpack 插件
16
+ 4. 增加 designSystem 配置
17
+
18
+ feat:
19
+
20
+ 1. core: add test method
21
+ 2. module plugins: add `babel`, `mainField`, `target` plugin
22
+ 3. storybook: change some logic and add tspath webpack plugin
23
+ 4. add `designSystem` config
24
+
25
+ - edd1cfb1af: feat: modernjs Access builder compiler
26
+ feat: modernjs 接入 builder 构建
27
+ - d5a31df781: refactor: remove unbundle configs and types
28
+
29
+ refactor: 移除 unbundle 相关的配置项和类型定义
30
+
31
+ - 543be9558e: feat: compile server loader and support handle loader request
32
+ feat: 编译 server loader 并支持处理 loader 的请求
33
+
34
+ ### Patch Changes
35
+
36
+ - cc971eabfc: refactor: move server plugin load logic in `@modern-js/core`
37
+ refactor:移除在 `@modern-js/core` 中的 server 插件加载逻辑
38
+ - 5b9049f: feat: inject async js chunk when streaming ssr
39
+ feat: streaming ssr 时, 注入 async 类型的 js chunk
40
+ - 92004d1: feat: support load chunks parallelly
41
+ feat: 支持并行加载 chunks
42
+ - b8bbe036c7: feat: change type logic
43
+ feat: 修改类型相关的逻辑
44
+ - 3bbea92b2a: feat: support Hook、Middleware new API
45
+ feat: 支持 Hook、Middleware 的新 API
46
+ - abf3421: fix(dev-server): isDepsExists add non pkgPath judege
47
+
48
+ 修复: isDepsExists 方法添加 package.json 不存在的兜底
49
+
50
+ - 14b712d: fix: use consistent alias type and default value across packages
51
+
52
+ fix: 在各个包中使用一致的 alias 类型定义和默认值
53
+
54
+ ## 2.0.0-beta.0
55
+
56
+ ### Major Changes
57
+
58
+ - dda38c9: chore: v2
59
+
60
+ ### Minor Changes
61
+
62
+ - edd1cfb1a: feat: modernjs Access builder compiler
63
+ feat: modernjs 接入 builder 构建
64
+ - d5a31df78: refactor: remove unbundle configs and types
65
+
66
+ refactor: 移除 unbundle 相关的配置项和类型定义
67
+
68
+ - 543be95: feat: compile server loader and support handle loader request
69
+ feat: 编译 server loader 并支持处理 loader 的请求
70
+
71
+ ### Patch Changes
72
+
73
+ - cc971eabf: refactor: move server plugin load logic in `@modern-js/core`
74
+ refactor:移除在 `@modern-js/core` 中的 server 插件加载逻辑
75
+ - 5b9049f: feat: inject async js chunk when streaming ssr
76
+ feat: streaming ssr 时, 注入 async 类型的 js chunk
77
+ - b8bbe036c: feat: change type logic
78
+ feat: 修改类型相关的逻辑
79
+ - 3bbea92b2: feat: support Hook、Middleware new API
80
+ feat: 支持 Hook、Middleware 的新 API
81
+ - abf3421: fix(dev-server): isDepsExists add non pkgPath judege
82
+
83
+ 修复: isDepsExists 方法添加 package.json 不存在的兜底
84
+
85
+ - 14b712d: fix: use consistent alias type and default value across packages
86
+
87
+ fix: 在各个包中使用一致的 alias 类型定义和默认值
8
88
 
9
89
  ## 1.21.2
10
90
 
package/dist/alias.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- declare type AliasOption = Record<string, string> | ((aliases: Record<string, string>) => Record<string, unknown>) | Record<string, string> | undefined;
1
+ export declare type Alias = Record<string, string | string[]>;
2
+ export declare type AliasOption = Alias | ((aliases: Alias) => Alias | void);
2
3
  interface NormalizedConfig {
3
4
  source: {
4
5
  alias?: AliasOption | Array<AliasOption>;
@@ -13,7 +14,8 @@ interface IAliasConfig {
13
14
  export declare const validAlias: <T extends NormalizedConfig>(modernConfig: T, { tsconfigPath }: {
14
15
  tsconfigPath: string;
15
16
  }) => string | null;
16
- export declare const getAlias: (aliasOption: AliasOption | Array<AliasOption>, option: {
17
+ export declare const mergeAlias: (alias: NormalizedConfig['source']['alias']) => Alias;
18
+ export declare const getAliasConfig: (aliasOption: NormalizedConfig['source']['alias'], option: {
17
19
  appDirectory: string;
18
20
  tsconfigPath: string;
19
21
  }) => IAliasConfig;
package/dist/alias.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getUserAlias = exports.getAlias = exports.validAlias = void 0;
6
+ exports.getUserAlias = exports.getAliasConfig = exports.mergeAlias = exports.validAlias = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const compiled_1 = require("./compiled");
@@ -25,36 +25,35 @@ const validAlias = (modernConfig, { tsconfigPath }) => {
25
25
  return null;
26
26
  };
27
27
  exports.validAlias = validAlias;
28
- const getAlias = (aliasOption, option) => {
28
+ const mergeAlias = (alias) => (0, applyOptionsChain_1.applyOptionsChain)({}, alias);
29
+ exports.mergeAlias = mergeAlias;
30
+ const getAliasConfig = (aliasOption, option) => {
29
31
  var _a, _b;
30
32
  const isTsProject = fs_1.default.existsSync(option.tsconfigPath);
31
- let aliasConfig;
33
+ const alias = (0, exports.mergeAlias)(aliasOption);
32
34
  if (!isTsProject) {
33
- aliasConfig = {
35
+ return {
34
36
  absoluteBaseUrl: option.appDirectory,
35
- paths: (0, applyOptionsChain_1.applyOptionsChain)({ '@': ['./src'] }, aliasOption),
37
+ paths: alias,
36
38
  isTsPath: false,
37
39
  isTsProject,
38
40
  };
39
41
  }
40
- else {
41
- const tsconfig = (0, readTsConfig_1.readTsConfigByFile)(option.tsconfigPath);
42
- const baseUrl = (_a = tsconfig === null || tsconfig === void 0 ? void 0 : tsconfig.compilerOptions) === null || _a === void 0 ? void 0 : _a.baseUrl;
43
- aliasConfig = {
44
- absoluteBaseUrl: baseUrl
45
- ? path_1.default.join(option.appDirectory, baseUrl)
46
- : option.appDirectory,
47
- paths: {
48
- ...(aliasOption || {}),
49
- ...(_b = tsconfig === null || tsconfig === void 0 ? void 0 : tsconfig.compilerOptions) === null || _b === void 0 ? void 0 : _b.paths,
50
- },
51
- isTsPath: true,
52
- isTsProject,
53
- };
54
- }
55
- return aliasConfig;
42
+ const tsconfig = (0, readTsConfig_1.readTsConfigByFile)(option.tsconfigPath);
43
+ const baseUrl = (_a = tsconfig === null || tsconfig === void 0 ? void 0 : tsconfig.compilerOptions) === null || _a === void 0 ? void 0 : _a.baseUrl;
44
+ return {
45
+ absoluteBaseUrl: baseUrl
46
+ ? path_1.default.join(option.appDirectory, baseUrl)
47
+ : option.appDirectory,
48
+ paths: {
49
+ ...alias,
50
+ ...(_b = tsconfig === null || tsconfig === void 0 ? void 0 : tsconfig.compilerOptions) === null || _b === void 0 ? void 0 : _b.paths,
51
+ },
52
+ isTsPath: true,
53
+ isTsProject,
54
+ };
56
55
  };
57
- exports.getAlias = getAlias;
56
+ exports.getAliasConfig = getAliasConfig;
58
57
  // filter invalid ts paths that are not array
59
58
  const getUserAlias = (alias = {}) => Object.keys(alias).reduce((o, k) => {
60
59
  if (Array.isArray(alias[k])) {
package/dist/chainId.d.ts CHANGED
@@ -31,6 +31,8 @@ export declare const CHAIN_ID: {
31
31
  readonly TOML: "toml";
32
32
  /** Rule for yaml */
33
33
  readonly YAML: "yaml";
34
+ /** Rule for bff */
35
+ readonly JS_BFF_API: "js-bff-api";
34
36
  };
35
37
  /** Predefined rule groups */
36
38
  readonly ONE_OF: {
@@ -83,12 +85,16 @@ export declare const CHAIN_ID: {
83
85
  readonly BABEL: "babel";
84
86
  /** esbuild-loader */
85
87
  readonly ESBUILD: "esbuild";
88
+ /** swc-loader */
89
+ readonly SWC: "swc";
86
90
  /** style-loader */
87
91
  readonly STYLE: "style-loader";
88
92
  /** postcss-loader */
89
93
  readonly POSTCSS: "postcss";
90
94
  /** markdown-loader */
91
95
  readonly MARKDOWN: "markdown";
96
+ /** ignore-css-loader */
97
+ readonly IGNORE_CSS: "ignore-css";
92
98
  /** css-modules-typescript-loader */
93
99
  readonly CSS_MODULES_TS: "css-modules-typescript";
94
100
  /** mini-css-extract-plugin.loader */
@@ -140,6 +146,8 @@ export declare const CHAIN_ID: {
140
146
  readonly ASSETS_RETRY: "ASSETS_RETRY";
141
147
  /** AutoSetRootFontSizePlugin */
142
148
  readonly AUTO_SET_ROOT_SIZE: "auto-set-root-size";
149
+ /** HtmlAsyncChunkPlugin */
150
+ readonly HTML_ASYNC_CHUNK: "html-async-chunk";
143
151
  };
144
152
  /** Predefined minimizers */
145
153
  readonly MINIMIZER: {
@@ -149,6 +157,8 @@ export declare const CHAIN_ID: {
149
157
  readonly CSS: "css";
150
158
  /** ESBuildPlugin */
151
159
  readonly ESBUILD: "js-css";
160
+ /** SWCPlugin */
161
+ readonly SWC: "swc";
152
162
  };
153
163
  /** Predefined resolve plugins */
154
164
  readonly RESOLVE_PLUGIN: {
package/dist/chainId.js CHANGED
@@ -34,6 +34,8 @@ exports.CHAIN_ID = {
34
34
  TOML: 'toml',
35
35
  /** Rule for yaml */
36
36
  YAML: 'yaml',
37
+ /** Rule for bff */
38
+ JS_BFF_API: 'js-bff-api',
37
39
  },
38
40
  /** Predefined rule groups */
39
41
  ONE_OF: {
@@ -86,12 +88,16 @@ exports.CHAIN_ID = {
86
88
  BABEL: 'babel',
87
89
  /** esbuild-loader */
88
90
  ESBUILD: 'esbuild',
91
+ /** swc-loader */
92
+ SWC: 'swc',
89
93
  /** style-loader */
90
94
  STYLE: 'style-loader',
91
95
  /** postcss-loader */
92
96
  POSTCSS: 'postcss',
93
97
  /** markdown-loader */
94
98
  MARKDOWN: 'markdown',
99
+ /** ignore-css-loader */
100
+ IGNORE_CSS: 'ignore-css',
95
101
  /** css-modules-typescript-loader */
96
102
  CSS_MODULES_TS: 'css-modules-typescript',
97
103
  /** mini-css-extract-plugin.loader */
@@ -143,6 +149,8 @@ exports.CHAIN_ID = {
143
149
  ASSETS_RETRY: 'ASSETS_RETRY',
144
150
  /** AutoSetRootFontSizePlugin */
145
151
  AUTO_SET_ROOT_SIZE: 'auto-set-root-size',
152
+ /** HtmlAsyncChunkPlugin */
153
+ HTML_ASYNC_CHUNK: 'html-async-chunk',
146
154
  },
147
155
  /** Predefined minimizers */
148
156
  MINIMIZER: {
@@ -152,6 +160,8 @@ exports.CHAIN_ID = {
152
160
  CSS: 'css',
153
161
  /** ESBuildPlugin */
154
162
  ESBUILD: 'js-css',
163
+ /** SWCPlugin */
164
+ SWC: 'swc',
155
165
  },
156
166
  /** Predefined resolve plugins */
157
167
  RESOLVE_PLUGIN: {
@@ -3,6 +3,9 @@
3
3
  * @param filePath - File to required.
4
4
  * @returns module export object.
5
5
  */
6
- export declare const compatRequire: (filePath: string) => any;
7
- export declare const requireExistModule: (filename: string, extensions?: string[]) => any;
6
+ export declare const compatRequire: (filePath: string, interop?: boolean) => any;
7
+ export declare const requireExistModule: (filename: string, opt?: {
8
+ extensions?: string[];
9
+ interop?: boolean;
10
+ }) => any;
8
11
  export declare const cleanRequireCache: (filelist: string[]) => void;
@@ -7,17 +7,23 @@ const findExists_1 = require("./findExists");
7
7
  * @param filePath - File to required.
8
8
  * @returns module export object.
9
9
  */
10
- const compatRequire = (filePath) => {
10
+ const compatRequire = (filePath, interop = true) => {
11
11
  const mod = require(filePath);
12
- return (mod === null || mod === void 0 ? void 0 : mod.__esModule) ? mod.default : mod;
12
+ const rtnESMDefault = interop && (mod === null || mod === void 0 ? void 0 : mod.__esModule);
13
+ return rtnESMDefault ? mod.default : mod;
13
14
  };
14
15
  exports.compatRequire = compatRequire;
15
- const requireExistModule = (filename, extensions = ['.ts', '.js']) => {
16
- const exist = (0, findExists_1.findExists)(extensions.map(ext => `${filename}${ext}`));
16
+ const requireExistModule = (filename, opt) => {
17
+ const final = {
18
+ extensions: ['.ts', '.js'],
19
+ interop: true,
20
+ ...opt,
21
+ };
22
+ const exist = (0, findExists_1.findExists)(final.extensions.map(ext => `${filename}${ext}`));
17
23
  if (!exist) {
18
24
  return null;
19
25
  }
20
- return (0, exports.compatRequire)(exist);
26
+ return (0, exports.compatRequire)(exist, final.interop);
21
27
  };
22
28
  exports.requireExistModule = requireExistModule;
23
29
  const cleanRequireCache = (filelist) => {
@@ -1,3 +1,4 @@
1
+ import { InternalPlugins } from '@modern-js/types';
1
2
  /**
2
3
  * hmr socket connect path
3
4
  */
@@ -49,15 +50,19 @@ export declare const OUTPUT_CONFIG_FILE = "modern.config.json";
49
50
  * Default server config basename
50
51
  */
51
52
  export declare const DEFAULT_SERVER_CONFIG = "modern.server-runtime.config";
53
+ /**
54
+ * Routes manifest filename
55
+ */
56
+ export declare const ROUTE_MINIFEST_FILE = "routes-manifest.json";
57
+ /**
58
+ * Property mounted on window that describes route manifest
59
+ */
60
+ export declare const ROUTE_MANIFEST = "_MODERNJS_ROUTE_MANIFEST";
52
61
  /**
53
62
  * Internal plugins that work as soon as they are installed.
54
63
  */
55
- export declare const INTERNAL_PLUGINS: {
56
- [name: string]: {
57
- cli?: string;
58
- server?: string;
59
- };
60
- };
64
+ export declare const INTERNAL_CLI_PLUGINS: InternalPlugins;
65
+ export declare const INTERNAL_SERVER_PLUGINS: InternalPlugins;
61
66
  /**
62
67
  * The schema registered in the plugin.
63
68
  */
@@ -104,24 +109,6 @@ export declare const PLUGIN_SCHEMAS: {
104
109
  };
105
110
  };
106
111
  }[];
107
- '@modern-js/plugin-esbuild': {
108
- target: string;
109
- schema: {
110
- typeof: string[];
111
- };
112
- }[];
113
- '@modern-js/plugin-less': {
114
- target: string;
115
- schema: {
116
- typeof: string[];
117
- };
118
- }[];
119
- '@modern-js/plugin-sass': {
120
- target: string;
121
- schema: {
122
- typeof: string[];
123
- };
124
- }[];
125
112
  '@modern-js/plugin-tailwindcss': {
126
113
  target: string;
127
114
  schema: {
@@ -134,35 +121,6 @@ export declare const PLUGIN_SCHEMAS: {
134
121
  typeof: string[];
135
122
  };
136
123
  }[];
137
- '@modern-js/plugin-unbundle': ({
138
- target: string;
139
- schema: {
140
- type: string;
141
- properties?: undefined;
142
- };
143
- } | {
144
- target: string;
145
- schema: {
146
- type: string;
147
- properties: {
148
- ignore: {
149
- type: string[];
150
- items: {
151
- type: string;
152
- };
153
- };
154
- ignoreModuleCache: {
155
- type: string;
156
- };
157
- clearPdnCache: {
158
- type: string;
159
- };
160
- pdnHost: {
161
- type: string;
162
- };
163
- };
164
- };
165
- })[];
166
124
  '@modern-js/plugin-ssg': {
167
125
  target: string;
168
126
  schema: {
package/dist/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PLUGIN_SCHEMAS = exports.INTERNAL_PLUGINS = exports.DEFAULT_SERVER_CONFIG = exports.OUTPUT_CONFIG_FILE = exports.CONFIG_FILE_EXTENSIONS = exports.CONFIG_CACHE_DIR = exports.SHARED_DIR = exports.SERVER_DIR = exports.API_DIR = exports.LOADABLE_STATS_FILE = exports.SERVER_RENDER_FUNCTION_NAME = exports.ENTRY_NAME_PATTERN = exports.SERVER_BUNDLE_DIRECTORY = exports.LAUNCH_EDITOR_ENDPOINT = exports.MAIN_ENTRY_NAME = exports.ROUTE_SPEC_FILE = exports.HMR_SOCK_PATH = void 0;
3
+ exports.PLUGIN_SCHEMAS = exports.INTERNAL_SERVER_PLUGINS = exports.INTERNAL_CLI_PLUGINS = exports.ROUTE_MANIFEST = exports.ROUTE_MINIFEST_FILE = exports.DEFAULT_SERVER_CONFIG = exports.OUTPUT_CONFIG_FILE = exports.CONFIG_FILE_EXTENSIONS = exports.CONFIG_CACHE_DIR = exports.SHARED_DIR = exports.SERVER_DIR = exports.API_DIR = exports.LOADABLE_STATS_FILE = exports.SERVER_RENDER_FUNCTION_NAME = exports.ENTRY_NAME_PATTERN = exports.SERVER_BUNDLE_DIRECTORY = exports.LAUNCH_EDITOR_ENDPOINT = exports.MAIN_ENTRY_NAME = exports.ROUTE_SPEC_FILE = exports.HMR_SOCK_PATH = void 0;
4
4
  /**
5
5
  * hmr socket connect path
6
6
  */
@@ -52,58 +52,49 @@ exports.OUTPUT_CONFIG_FILE = 'modern.config.json';
52
52
  * Default server config basename
53
53
  */
54
54
  exports.DEFAULT_SERVER_CONFIG = 'modern.server-runtime.config';
55
+ /**
56
+ * Routes manifest filename
57
+ */
58
+ exports.ROUTE_MINIFEST_FILE = 'routes-manifest.json';
59
+ /**
60
+ * Property mounted on window that describes route manifest
61
+ */
62
+ exports.ROUTE_MANIFEST = `_MODERNJS_ROUTE_MANIFEST`;
55
63
  /**
56
64
  * Internal plugins that work as soon as they are installed.
57
65
  */
58
- exports.INTERNAL_PLUGINS = {
59
- '@modern-js/app-tools': { cli: '@modern-js/app-tools/cli' },
60
- '@modern-js/monorepo-tools': { cli: '@modern-js/monorepo-tools/cli' },
61
- '@modern-js/module-tools': { cli: '@modern-js/module-tools/cli' },
62
- '@modern-js/runtime': { cli: '@modern-js/runtime/cli' },
63
- '@modern-js/plugin-less': { cli: '@modern-js/plugin-less/cli' },
64
- '@modern-js/plugin-sass': { cli: '@modern-js/plugin-sass/cli' },
65
- '@modern-js/plugin-esbuild': { cli: '@modern-js/plugin-esbuild/cli' },
66
- '@modern-js/plugin-proxy': { cli: '@modern-js/plugin-proxy/cli' },
67
- '@modern-js/plugin-ssg': { cli: '@modern-js/plugin-ssg/cli' },
68
- '@modern-js/plugin-bff': {
69
- cli: '@modern-js/plugin-bff/cli',
70
- server: '@modern-js/plugin-bff/server',
71
- },
72
- '@modern-js/plugin-electron': { cli: '@modern-js/plugin-electron/cli' },
73
- '@modern-js/plugin-testing': { cli: '@modern-js/plugin-testing/cli' },
74
- '@modern-js/plugin-storybook': { cli: '@modern-js/plugin-storybook/cli' },
75
- '@modern-js/plugin-express': {
76
- cli: '@modern-js/plugin-express/cli',
77
- server: '@modern-js/plugin-express',
78
- },
79
- '@modern-js/plugin-egg': {
80
- cli: '@modern-js/plugin-egg/cli',
81
- server: '@modern-js/plugin-egg',
82
- },
83
- '@modern-js/plugin-koa': {
84
- cli: '@modern-js/plugin-koa/cli',
85
- server: '@modern-js/plugin-koa',
86
- },
87
- '@modern-js/plugin-nest': {
88
- cli: '@modern-js/plugin-nest/cli',
89
- server: '@modern-js/plugin-nest/server',
90
- },
91
- // TODO: remove unbundle configs after we completely deprecate it.
92
- '@modern-js/plugin-unbundle': { cli: '@modern-js/plugin-unbundle' },
93
- '@modern-js/plugin-server': {
94
- cli: '@modern-js/plugin-server/cli',
95
- server: '@modern-js/plugin-server/server',
96
- },
97
- '@modern-js/plugin-garfish': {
98
- cli: '@modern-js/plugin-garfish/cli',
99
- },
100
- '@modern-js/plugin-tailwindcss': { cli: '@modern-js/plugin-tailwindcss/cli' },
101
- '@modern-js/plugin-polyfill': {
102
- cli: '@modern-js/plugin-polyfill/cli',
103
- server: '@modern-js/plugin-polyfill',
104
- },
66
+ exports.INTERNAL_CLI_PLUGINS = {
67
+ '@modern-js/app-tools': '@modern-js/app-tools/cli',
68
+ '@modern-js/monorepo-tools': '@modern-js/monorepo-tools/cli',
69
+ '@modern-js/module-tools': '@modern-js/module-tools/cli',
70
+ '@modern-js/module-tools-v2': '@modern-js/module-tools-v2',
71
+ '@modern-js/runtime': '@modern-js/runtime/cli',
72
+ '@modern-js/plugin-proxy': '@modern-js/plugin-proxy/cli',
73
+ '@modern-js/plugin-ssg': '@modern-js/plugin-ssg/cli',
74
+ '@modern-js/plugin-bff': '@modern-js/plugin-bff/cli',
75
+ '@modern-js/plugin-testing': '@modern-js/plugin-testing/cli',
76
+ '@modern-js/plugin-storybook': '@modern-js/plugin-storybook/cli',
77
+ '@modern-js/plugin-express': '@modern-js/plugin-express/cli',
78
+ '@modern-js/plugin-egg': '@modern-js/plugin-egg/cli',
79
+ '@modern-js/plugin-koa': '@modern-js/plugin-koa/cli',
80
+ '@modern-js/plugin-nest': '@modern-js/plugin-nest/cli',
81
+ '@modern-js/plugin-server': '@modern-js/plugin-server/cli',
82
+ '@modern-js/plugin-garfish': '@modern-js/plugin-garfish/cli',
83
+ '@modern-js/plugin-tailwindcss': '@modern-js/plugin-tailwindcss/cli',
84
+ '@modern-js/plugin-polyfill': '@modern-js/plugin-polyfill/cli',
105
85
  // TODO: Maybe can remove it
106
- '@modern-js/plugin-nocode': { cli: '@modern-js/plugin-nocode/cli' },
86
+ '@modern-js/plugin-nocode': '@modern-js/plugin-nocode/cli',
87
+ // legacy router (inner react-router-dom v5)
88
+ '@modern-js/plugin-router-legacy': '@modern-js/plugin-router-legacy/cli',
89
+ };
90
+ exports.INTERNAL_SERVER_PLUGINS = {
91
+ '@modern-js/plugin-bff': '@modern-js/plugin-bff/server',
92
+ '@modern-js/plugin-express': '@modern-js/plugin-express',
93
+ '@modern-js/plugin-egg': '@modern-js/plugin-egg',
94
+ '@modern-js/plugin-koa': '@modern-js/plugin-koa',
95
+ '@modern-js/plugin-nest': '@modern-js/plugin-nest/server',
96
+ '@modern-js/plugin-server': '@modern-js/plugin-server/server',
97
+ '@modern-js/plugin-polyfill': '@modern-js/plugin-polyfill',
107
98
  };
108
99
  /**
109
100
  * The schema registered in the plugin.
@@ -143,24 +134,6 @@ exports.PLUGIN_SCHEMAS = {
143
134
  },
144
135
  },
145
136
  ],
146
- '@modern-js/plugin-esbuild': [
147
- {
148
- target: 'tools.esbuild',
149
- schema: { typeof: ['object'] },
150
- },
151
- ],
152
- '@modern-js/plugin-less': [
153
- {
154
- target: 'tools.less',
155
- schema: { typeof: ['object', 'function'] },
156
- },
157
- ],
158
- '@modern-js/plugin-sass': [
159
- {
160
- target: 'tools.sass',
161
- schema: { typeof: ['object', 'function'] },
162
- },
163
- ],
164
137
  '@modern-js/plugin-tailwindcss': [
165
138
  {
166
139
  target: 'tools.tailwindcss',
@@ -173,28 +146,6 @@ exports.PLUGIN_SCHEMAS = {
173
146
  schema: { typeof: ['string', 'object'] },
174
147
  },
175
148
  ],
176
- // TODO: remove unbundle configs after we completely deprecate it.
177
- '@modern-js/plugin-unbundle': [
178
- {
179
- target: 'output.disableAutoImportStyle',
180
- schema: { type: 'boolean' },
181
- },
182
- {
183
- target: 'dev.unbundle',
184
- schema: {
185
- type: 'object',
186
- properties: {
187
- ignore: {
188
- type: ['string', 'array'],
189
- items: { type: 'string' },
190
- },
191
- ignoreModuleCache: { type: 'boolean' },
192
- clearPdnCache: { type: 'boolean' },
193
- pdnHost: { type: 'string' },
194
- },
195
- },
196
- },
197
- ],
198
149
  '@modern-js/plugin-ssg': [
199
150
  {
200
151
  target: 'output.ssg',
@@ -223,6 +174,10 @@ exports.PLUGIN_SCHEMAS = {
223
174
  target: 'source.designSystem.supportStyledComponents',
224
175
  schema: { type: ['boolean'] },
225
176
  },
177
+ {
178
+ target: 'designSystem',
179
+ schema: { typeof: ['object'] },
180
+ },
226
181
  ],
227
182
  '@modern-js/plugin-router': [
228
183
  {
package/dist/format.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  * https://github.com/facebook/create-react-app/blob/master/LICENSE
7
7
  */
8
8
  import type { StatsCompilation } from 'webpack';
9
- declare function formatWebpackMessages(json: StatsCompilation): {
9
+ declare function formatWebpackMessages(json?: Pick<StatsCompilation, 'errors' | 'warnings'>): {
10
10
  errors: string[];
11
11
  warnings: string[];
12
12
  };
package/dist/format.js CHANGED
@@ -69,8 +69,8 @@ function formatMessage(stats) {
69
69
  }
70
70
  function formatWebpackMessages(json) {
71
71
  var _a, _b, _c;
72
- const formattedErrors = (_a = json.errors) === null || _a === void 0 ? void 0 : _a.map(formatMessage);
73
- const formattedWarnings = (_b = json.warnings) === null || _b === void 0 ? void 0 : _b.map(formatMessage);
72
+ const formattedErrors = (_a = json === null || json === void 0 ? void 0 : json.errors) === null || _a === void 0 ? void 0 : _a.map(formatMessage);
73
+ const formattedWarnings = (_b = json === null || json === void 0 ? void 0 : json.warnings) === null || _b === void 0 ? void 0 : _b.map(formatMessage);
74
74
  const result = {
75
75
  errors: formattedErrors || [],
76
76
  warnings: formattedWarnings || [],
package/dist/index.d.ts CHANGED
@@ -21,6 +21,7 @@ export * from './getPackageManager';
21
21
  export * from './runtimeExports';
22
22
  export * from './readTsConfig';
23
23
  export * from './path';
24
+ export * from './pathSerializer';
24
25
  export * from './generateMetaTags';
25
26
  export * from './prettyInstructions';
26
27
  export * from './alias';
@@ -35,3 +36,5 @@ export * from './tryResolve';
35
36
  export * from './analyzeProject';
36
37
  export * from './chainId';
37
38
  export * from './version';
39
+ export * from './plugin';
40
+ export * from './routes';
package/dist/index.js CHANGED
@@ -37,6 +37,7 @@ __exportStar(require("./getPackageManager"), exports);
37
37
  __exportStar(require("./runtimeExports"), exports);
38
38
  __exportStar(require("./readTsConfig"), exports);
39
39
  __exportStar(require("./path"), exports);
40
+ __exportStar(require("./pathSerializer"), exports);
40
41
  __exportStar(require("./generateMetaTags"), exports);
41
42
  __exportStar(require("./prettyInstructions"), exports);
42
43
  __exportStar(require("./alias"), exports);
@@ -51,3 +52,5 @@ __exportStar(require("./tryResolve"), exports);
51
52
  __exportStar(require("./analyzeProject"), exports);
52
53
  __exportStar(require("./chainId"), exports);
53
54
  __exportStar(require("./version"), exports);
55
+ __exportStar(require("./plugin"), exports);
56
+ __exportStar(require("./routes"), exports);
package/dist/is/index.js CHANGED
@@ -20,7 +20,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.isFastRefresh = exports.isUseSSRBundle = exports.isSSR = exports.isEmpty = exports.isTypescript = exports.isDepExists = void 0;
21
21
  const fs_1 = __importDefault(require("fs"));
22
22
  const path_1 = __importDefault(require("path"));
23
+ const debug_1 = require("../debug");
23
24
  const node_env_1 = require("./node-env");
25
+ const debug = (0, debug_1.createDebugger)('judge-depExists');
24
26
  /**
25
27
  * Check if the package name is in dependencies or devDependencies.
26
28
  *
@@ -29,7 +31,12 @@ const node_env_1 = require("./node-env");
29
31
  * @returns True if the name is in dependencies or devDependencies, false otherwise.
30
32
  */
31
33
  const isDepExists = (appDirectory, name) => {
32
- const json = require(path_1.default.resolve(appDirectory, './package.json'));
34
+ const pkgPath = path_1.default.resolve(appDirectory, './package.json');
35
+ if (!fs_1.default.existsSync(pkgPath)) {
36
+ debug(`can't find package.json under: %s`, appDirectory);
37
+ return false;
38
+ }
39
+ const json = require(pkgPath);
33
40
  const { dependencies = {}, devDependencies = {} } = json;
34
41
  return (dependencies.hasOwnProperty(name) || devDependencies.hasOwnProperty(name));
35
42
  };
package/dist/path.d.ts CHANGED
@@ -1,5 +1,16 @@
1
+ import { lodash as _ } from './compiled';
1
2
  export declare const isPathString: (test: string) => boolean;
2
3
  export declare const isRelativePath: (test: string) => boolean;
3
4
  export declare const normalizeOutputPath: (s: string) => string;
4
5
  export declare const normalizeToPosixPath: (p: string | undefined) => string;
5
6
  export declare const getTemplatePath: (prefix?: string) => string;
7
+ /**
8
+ * Compile path string to RegExp.
9
+ * @note Only support posix path.
10
+ */
11
+ export declare function compilePathMatcherRegExp(match: string | RegExp): RegExp;
12
+ /** @internal @see {@link upwardPaths} */
13
+ export declare const _joinPathParts: (_part: unknown, i: number, parts: _.List<string>) => string;
14
+ export declare function upwardPaths(start: string): string[];
15
+ export declare function getRealTemporaryDirectory(): string | null;
16
+ export declare function splitPathString(str: string): string[];
package/dist/path.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getTemplatePath = exports.normalizeToPosixPath = exports.normalizeOutputPath = exports.isRelativePath = exports.isPathString = void 0;
6
+ exports.splitPathString = exports.getRealTemporaryDirectory = exports.upwardPaths = exports._joinPathParts = exports.compilePathMatcherRegExp = exports.getTemplatePath = exports.normalizeToPosixPath = exports.normalizeOutputPath = exports.isRelativePath = exports.isPathString = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const os_1 = __importDefault(require("os"));
9
9
  const fs_1 = __importDefault(require("fs"));
@@ -26,3 +26,46 @@ const getTemplatePath = (prefix) => {
26
26
  return path_1.default.resolve(...parts);
27
27
  };
28
28
  exports.getTemplatePath = getTemplatePath;
29
+ /**
30
+ * Compile path string to RegExp.
31
+ * @note Only support posix path.
32
+ */
33
+ function compilePathMatcherRegExp(match) {
34
+ if (typeof match !== 'string') {
35
+ return match;
36
+ }
37
+ const escaped = compiled_1.lodash.escapeRegExp(match);
38
+ return new RegExp(`(?<=\\W|^)${escaped}(?=\\W|$)`);
39
+ }
40
+ exports.compilePathMatcherRegExp = compilePathMatcherRegExp;
41
+ /** @internal @see {@link upwardPaths} */
42
+ const _joinPathParts = (_part, i, parts) => (0, compiled_1.lodash)(parts)
43
+ .filter(part => !['/', '\\'].includes(part))
44
+ .tap(parts => parts.unshift(''))
45
+ .slice(0, i + 2)
46
+ .join('/');
47
+ exports._joinPathParts = _joinPathParts;
48
+ function upwardPaths(start) {
49
+ return (0, compiled_1.lodash)(start)
50
+ .split(/[/\\]/)
51
+ .filter(Boolean)
52
+ .map(exports._joinPathParts)
53
+ .reverse()
54
+ .push('/')
55
+ .value();
56
+ }
57
+ exports.upwardPaths = upwardPaths;
58
+ function getRealTemporaryDirectory() {
59
+ let ret = null;
60
+ try {
61
+ ret = os_1.default.tmpdir();
62
+ ret = fs_1.default.realpathSync(ret);
63
+ }
64
+ catch { }
65
+ return ret;
66
+ }
67
+ exports.getRealTemporaryDirectory = getRealTemporaryDirectory;
68
+ function splitPathString(str) {
69
+ return str.split(/[\\/]/);
70
+ }
71
+ exports.splitPathString = splitPathString;
@@ -0,0 +1,16 @@
1
+ /** Different from */
2
+ export declare type PathMatchExpression = string | RegExp;
3
+ export interface PathMatcher {
4
+ match: PathMatchExpression;
5
+ mark: string | ((substring: string, ...args: any[]) => string);
6
+ }
7
+ export declare const matchUpwardPathsAsUnknown: (p: string) => {
8
+ match: string;
9
+ mark: string;
10
+ }[];
11
+ export interface ApplyPathMatcherOptions {
12
+ minPartials?: number;
13
+ }
14
+ export declare function applyPathMatcher(matcher: PathMatcher, str: string, options?: ApplyPathMatcherOptions): string;
15
+ export declare function applyMatcherReplacement(matchers: PathMatcher[], str: string, options?: ApplyPathMatcherOptions): string;
16
+ export declare const createDefaultPathMatchers: (root: string) => PathMatcher[];
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createDefaultPathMatchers = exports.applyMatcherReplacement = exports.applyPathMatcher = exports.matchUpwardPathsAsUnknown = void 0;
7
+ const os_1 = __importDefault(require("os"));
8
+ const lodash_1 = __importDefault(require("../compiled/lodash"));
9
+ const path_1 = require("./path");
10
+ const matchUpwardPathsAsUnknown = (p) => (0, lodash_1.default)((0, path_1.upwardPaths)((0, path_1.normalizeToPosixPath)(p)))
11
+ .map(match => ({ match, mark: 'unknown' }))
12
+ .slice(1, -1)
13
+ .value();
14
+ exports.matchUpwardPathsAsUnknown = matchUpwardPathsAsUnknown;
15
+ function applyPathMatcher(matcher, str, options = {}) {
16
+ const regex = (0, path_1.compilePathMatcherRegExp)(matcher.match);
17
+ const replacer = (substring, ...args) => {
18
+ if (options.minPartials &&
19
+ (0, path_1.splitPathString)(substring).length < options.minPartials) {
20
+ return substring;
21
+ }
22
+ const ret = typeof matcher.mark === 'string'
23
+ ? matcher.mark
24
+ : matcher.mark(substring, ...args);
25
+ return `<${lodash_1.default.snakeCase(ret).toUpperCase()}>`;
26
+ };
27
+ return str.replace(regex, replacer);
28
+ }
29
+ exports.applyPathMatcher = applyPathMatcher;
30
+ function applyMatcherReplacement(matchers, str, options = {}) {
31
+ return matchers.reduce((ret, matcher) => {
32
+ return applyPathMatcher(matcher, ret, options);
33
+ }, str);
34
+ }
35
+ exports.applyMatcherReplacement = applyMatcherReplacement;
36
+ const createDefaultPathMatchers = (root) => {
37
+ const ret = [
38
+ {
39
+ match: /(?<=\/)(\.pnpm\/.+?\/node_modules)(?=\/)/,
40
+ mark: 'pnpmInner',
41
+ },
42
+ ];
43
+ const tmpdir = (0, path_1.getRealTemporaryDirectory)();
44
+ tmpdir && ret.push({ match: tmpdir, mark: 'temp' });
45
+ ret.push({ match: os_1.default.tmpdir(), mark: 'temp' });
46
+ ret.push({ match: os_1.default.homedir(), mark: 'home' });
47
+ ret.push(...(0, exports.matchUpwardPathsAsUnknown)(root));
48
+ return ret;
49
+ };
50
+ exports.createDefaultPathMatchers = createDefaultPathMatchers;
@@ -0,0 +1,2 @@
1
+ import { InternalPlugins } from '@modern-js/types';
2
+ export declare function getInternalPlugins(appDirectory: string, internalPlugins?: InternalPlugins): string[];
package/dist/plugin.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getInternalPlugins = void 0;
4
+ const constants_1 = require("./constants");
5
+ const is_1 = require("./is");
6
+ function getInternalPlugins(appDirectory, internalPlugins = constants_1.INTERNAL_CLI_PLUGINS) {
7
+ return [
8
+ ...Object.keys(internalPlugins)
9
+ .filter(name => {
10
+ const config = internalPlugins[name];
11
+ if (typeof config !== 'string' && config.forced === true) {
12
+ return true;
13
+ }
14
+ return (0, is_1.isDepExists)(appDirectory, name);
15
+ })
16
+ .map(name => {
17
+ const config = internalPlugins[name];
18
+ if (typeof config !== 'string') {
19
+ return config.path;
20
+ }
21
+ else {
22
+ return config;
23
+ }
24
+ }),
25
+ ];
26
+ }
27
+ exports.getInternalPlugins = getInternalPlugins;
@@ -0,0 +1,2 @@
1
+ export declare const getPathWithoutExt: (filename: string) => string;
2
+ export declare const getRouteId: (componentPath: string, routesDir: string, entryName: string) => string;
package/dist/routes.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getRouteId = exports.getPathWithoutExt = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const path_2 = require("./path");
9
+ const getPathWithoutExt = (filename) => {
10
+ const extname = path_1.default.extname(filename);
11
+ return filename.slice(0, -extname.length);
12
+ };
13
+ exports.getPathWithoutExt = getPathWithoutExt;
14
+ const getRouteId = (componentPath, routesDir, entryName) => {
15
+ const relativePath = (0, path_2.normalizeToPosixPath)(path_1.default.relative(routesDir, componentPath));
16
+ const pathWithoutExt = (0, exports.getPathWithoutExt)(relativePath);
17
+ const id = `${entryName}_${pathWithoutExt}`;
18
+ return id;
19
+ };
20
+ exports.getRouteId = getRouteId;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.21.5",
14
+ "version": "2.0.0-beta.1",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/index.d.ts",
17
17
  "main": "./dist/index.js",
@@ -134,38 +134,15 @@
134
134
  "typescript": "^4",
135
135
  "jest": "^27",
136
136
  "webpack": "^5.74.0",
137
- "@modern-js/types": "1.21.5",
138
- "@scripts/build": "1.21.5",
139
- "@scripts/jest-config": "1.21.5"
137
+ "@modern-js/types": "2.0.0-beta.1",
138
+ "@scripts/build": "2.0.0-beta.1",
139
+ "@scripts/jest-config": "2.0.0-beta.1"
140
140
  },
141
141
  "sideEffects": false,
142
- "wireit": {
143
- "build": {
144
- "command": "tsc",
145
- "files": [
146
- "src/**/*",
147
- "tsconfig.json",
148
- "package.json"
149
- ],
150
- "output": [
151
- "dist/**/*"
152
- ]
153
- },
154
- "test": {
155
- "command": "jest --passWithNoTests",
156
- "files": [
157
- "src/**/*",
158
- "tsconfig.json",
159
- "package.json",
160
- "tests/**/*"
161
- ],
162
- "output": []
163
- }
164
- },
165
142
  "scripts": {
166
143
  "new": "modern new",
167
144
  "dev": "tsc --watch",
168
- "build": "wireit",
169
- "test": "wireit"
145
+ "build": "tsc",
146
+ "test": "jest --passWithNoTests"
170
147
  }
171
148
  }