@modern-js/utils 1.21.2 → 2.0.0-beta.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +35 -0
- package/dist/alias.d.ts +4 -2
- package/dist/alias.js +21 -22
- package/dist/chainId.d.ts +10 -0
- package/dist/chainId.js +10 -0
- package/dist/compatRequire.d.ts +5 -2
- package/dist/compatRequire.js +11 -5
- package/dist/constants.d.ts +3 -53
- package/dist/constants.js +32 -89
- package/dist/format.d.ts +1 -1
- package/dist/format.js +2 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/is/index.js +8 -1
- package/dist/path.d.ts +11 -0
- package/dist/path.js +44 -1
- package/dist/pathSerializer.d.ts +16 -0
- package/dist/pathSerializer.js +50 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.js +27 -0
- package/dist/routes.d.ts +2 -0
- package/dist/routes.js +19 -0
- package/package.json +6 -29
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,40 @@
|
|
1
1
|
# @modern-js/utils
|
2
2
|
|
3
|
+
## 2.0.0-beta.0
|
4
|
+
|
5
|
+
### Major Changes
|
6
|
+
|
7
|
+
- dda38c9: chore: v2
|
8
|
+
|
9
|
+
### Minor Changes
|
10
|
+
|
11
|
+
- edd1cfb1a: feat: modernjs Access builder compiler
|
12
|
+
feat: modernjs 接入 builder 构建
|
13
|
+
- d5a31df78: refactor: remove unbundle configs and types
|
14
|
+
|
15
|
+
refactor: 移除 unbundle 相关的配置项和类型定义
|
16
|
+
|
17
|
+
- 543be95: feat: compile server loader and support handle loader request
|
18
|
+
feat: 编译 server loader 并支持处理 loader 的请求
|
19
|
+
|
20
|
+
### Patch Changes
|
21
|
+
|
22
|
+
- cc971eabf: refactor: move server plugin load logic in `@modern-js/core`
|
23
|
+
refactor:移除在 `@modern-js/core` 中的 server 插件加载逻辑
|
24
|
+
- 5b9049f: feat: inject async js chunk when streaming ssr
|
25
|
+
feat: streaming ssr 时, 注入 async 类型的 js chunk
|
26
|
+
- b8bbe036c: feat: change type logic
|
27
|
+
feat: 修改类型相关的逻辑
|
28
|
+
- 3bbea92b2: feat: support Hook、Middleware new API
|
29
|
+
feat: 支持 Hook、Middleware 的新 API
|
30
|
+
- abf3421: fix(dev-server): isDepsExists add non pkgPath judege
|
31
|
+
|
32
|
+
修复: isDepsExists 方法添加 package.json 不存在的兜底
|
33
|
+
|
34
|
+
- 14b712d: fix: use consistent alias type and default value across packages
|
35
|
+
|
36
|
+
fix: 在各个包中使用一致的 alias 类型定义和默认值
|
37
|
+
|
3
38
|
## 1.21.2
|
4
39
|
|
5
40
|
## 1.21.1
|
package/dist/alias.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
declare type
|
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
|
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.
|
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
|
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
|
-
|
33
|
+
const alias = (0, exports.mergeAlias)(aliasOption);
|
32
34
|
if (!isTsProject) {
|
33
|
-
|
35
|
+
return {
|
34
36
|
absoluteBaseUrl: option.appDirectory,
|
35
|
-
paths:
|
37
|
+
paths: alias,
|
36
38
|
isTsPath: false,
|
37
39
|
isTsProject,
|
38
40
|
};
|
39
41
|
}
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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.
|
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: {
|
package/dist/compatRequire.d.ts
CHANGED
@@ -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,
|
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;
|
package/dist/compatRequire.js
CHANGED
@@ -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
|
-
|
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,
|
16
|
-
const
|
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) => {
|
package/dist/constants.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { InternalPlugins } from '@modern-js/types';
|
1
2
|
/**
|
2
3
|
* hmr socket connect path
|
3
4
|
*/
|
@@ -52,12 +53,8 @@ export declare const DEFAULT_SERVER_CONFIG = "modern.server-runtime.config";
|
|
52
53
|
/**
|
53
54
|
* Internal plugins that work as soon as they are installed.
|
54
55
|
*/
|
55
|
-
export declare const
|
56
|
-
|
57
|
-
cli?: string;
|
58
|
-
server?: string;
|
59
|
-
};
|
60
|
-
};
|
56
|
+
export declare const INTERNAL_CLI_PLUGINS: InternalPlugins;
|
57
|
+
export declare const INTERNAL_SERVER_PLUGINS: InternalPlugins;
|
61
58
|
/**
|
62
59
|
* The schema registered in the plugin.
|
63
60
|
*/
|
@@ -104,24 +101,6 @@ export declare const PLUGIN_SCHEMAS: {
|
|
104
101
|
};
|
105
102
|
};
|
106
103
|
}[];
|
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
104
|
'@modern-js/plugin-tailwindcss': {
|
126
105
|
target: string;
|
127
106
|
schema: {
|
@@ -134,35 +113,6 @@ export declare const PLUGIN_SCHEMAS: {
|
|
134
113
|
typeof: string[];
|
135
114
|
};
|
136
115
|
}[];
|
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
116
|
'@modern-js/plugin-ssg': {
|
167
117
|
target: string;
|
168
118
|
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.
|
3
|
+
exports.PLUGIN_SCHEMAS = exports.INTERNAL_SERVER_PLUGINS = exports.INTERNAL_CLI_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;
|
4
4
|
/**
|
5
5
|
* hmr socket connect path
|
6
6
|
*/
|
@@ -55,55 +55,38 @@ exports.DEFAULT_SERVER_CONFIG = 'modern.server-runtime.config';
|
|
55
55
|
/**
|
56
56
|
* Internal plugins that work as soon as they are installed.
|
57
57
|
*/
|
58
|
-
exports.
|
59
|
-
'@modern-js/app-tools':
|
60
|
-
'@modern-js/monorepo-tools':
|
61
|
-
'@modern-js/module-tools':
|
62
|
-
'@modern-js/
|
63
|
-
'@modern-js/
|
64
|
-
'@modern-js/plugin-
|
65
|
-
'@modern-js/plugin-
|
66
|
-
'@modern-js/plugin-
|
67
|
-
'@modern-js/plugin-
|
68
|
-
'@modern-js/plugin-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
'@modern-js/plugin-
|
73
|
-
'@modern-js/plugin-
|
74
|
-
'@modern-js/plugin-
|
75
|
-
'@modern-js/plugin-
|
76
|
-
|
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
|
-
},
|
58
|
+
exports.INTERNAL_CLI_PLUGINS = {
|
59
|
+
'@modern-js/app-tools': '@modern-js/app-tools/cli',
|
60
|
+
'@modern-js/monorepo-tools': '@modern-js/monorepo-tools/cli',
|
61
|
+
'@modern-js/module-tools': '@modern-js/module-tools/cli',
|
62
|
+
'@modern-js/module-tools-v2': '@modern-js/module-tools-v2',
|
63
|
+
'@modern-js/runtime': '@modern-js/runtime/cli',
|
64
|
+
'@modern-js/plugin-proxy': '@modern-js/plugin-proxy/cli',
|
65
|
+
'@modern-js/plugin-ssg': '@modern-js/plugin-ssg/cli',
|
66
|
+
'@modern-js/plugin-bff': '@modern-js/plugin-bff/cli',
|
67
|
+
'@modern-js/plugin-testing': '@modern-js/plugin-testing/cli',
|
68
|
+
'@modern-js/plugin-storybook': '@modern-js/plugin-storybook/cli',
|
69
|
+
'@modern-js/plugin-express': '@modern-js/plugin-express/cli',
|
70
|
+
'@modern-js/plugin-egg': '@modern-js/plugin-egg/cli',
|
71
|
+
'@modern-js/plugin-koa': '@modern-js/plugin-koa/cli',
|
72
|
+
'@modern-js/plugin-nest': '@modern-js/plugin-nest/cli',
|
73
|
+
'@modern-js/plugin-server': '@modern-js/plugin-server/cli',
|
74
|
+
'@modern-js/plugin-garfish': '@modern-js/plugin-garfish/cli',
|
75
|
+
'@modern-js/plugin-tailwindcss': '@modern-js/plugin-tailwindcss/cli',
|
76
|
+
'@modern-js/plugin-polyfill': '@modern-js/plugin-polyfill/cli',
|
105
77
|
// TODO: Maybe can remove it
|
106
|
-
'@modern-js/plugin-nocode':
|
78
|
+
'@modern-js/plugin-nocode': '@modern-js/plugin-nocode/cli',
|
79
|
+
// legacy router (inner react-router-dom v5)
|
80
|
+
'@modern-js/plugin-router-legacy': '@modern-js/plugin-router-legacy/cli',
|
81
|
+
};
|
82
|
+
exports.INTERNAL_SERVER_PLUGINS = {
|
83
|
+
'@modern-js/plugin-bff': '@modern-js/plugin-bff/server',
|
84
|
+
'@modern-js/plugin-express': '@modern-js/plugin-express',
|
85
|
+
'@modern-js/plugin-egg': '@modern-js/plugin-egg',
|
86
|
+
'@modern-js/plugin-koa': '@modern-js/plugin-koa',
|
87
|
+
'@modern-js/plugin-nest': '@modern-js/plugin-nest/server',
|
88
|
+
'@modern-js/plugin-server': '@modern-js/plugin-server/server',
|
89
|
+
'@modern-js/plugin-polyfill': '@modern-js/plugin-polyfill',
|
107
90
|
};
|
108
91
|
/**
|
109
92
|
* The schema registered in the plugin.
|
@@ -143,24 +126,6 @@ exports.PLUGIN_SCHEMAS = {
|
|
143
126
|
},
|
144
127
|
},
|
145
128
|
],
|
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
129
|
'@modern-js/plugin-tailwindcss': [
|
165
130
|
{
|
166
131
|
target: 'tools.tailwindcss',
|
@@ -173,28 +138,6 @@ exports.PLUGIN_SCHEMAS = {
|
|
173
138
|
schema: { typeof: ['string', 'object'] },
|
174
139
|
},
|
175
140
|
],
|
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
141
|
'@modern-js/plugin-ssg': [
|
199
142
|
{
|
200
143
|
target: 'output.ssg',
|
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
|
9
|
+
declare function formatWebpackMessages(json?: StatsCompilation): {
|
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
|
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;
|
package/dist/plugin.d.ts
ADDED
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;
|
package/dist/routes.d.ts
ADDED
package/dist/routes.js
ADDED
@@ -0,0 +1,19 @@
|
|
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) => {
|
15
|
+
const relativePath = (0, path_2.normalizeToPosixPath)(path_1.default.relative(routesDir, componentPath));
|
16
|
+
const id = (0, exports.getPathWithoutExt)(relativePath);
|
17
|
+
return id;
|
18
|
+
};
|
19
|
+
exports.getRouteId = getRouteId;
|
package/package.json
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "
|
14
|
+
"version": "2.0.0-beta.0",
|
15
15
|
"jsnext:source": "./src/index.ts",
|
16
16
|
"types": "./dist/index.d.ts",
|
17
17
|
"main": "./dist/index.js",
|
@@ -129,9 +129,9 @@
|
|
129
129
|
"lodash": "^4.17.21"
|
130
130
|
},
|
131
131
|
"devDependencies": {
|
132
|
-
"@modern-js/types": "
|
133
|
-
"@scripts/build": "
|
134
|
-
"@scripts/jest-config": "
|
132
|
+
"@modern-js/types": "2.0.0-beta.0",
|
133
|
+
"@scripts/build": "2.0.0-beta.0",
|
134
|
+
"@scripts/jest-config": "2.0.0-beta.0",
|
135
135
|
"@types/jest": "^27",
|
136
136
|
"@types/node": "^14",
|
137
137
|
"typescript": "^4",
|
@@ -139,33 +139,10 @@
|
|
139
139
|
"webpack": "^5.74.0"
|
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": "
|
169
|
-
"test": "
|
145
|
+
"build": "tsc",
|
146
|
+
"test": "jest --passWithNoTests"
|
170
147
|
}
|
171
148
|
}
|