@modern-js/utils 1.1.7-alpha.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +40 -0
- package/dist/js/modern/clearConsole.js +1 -1
- package/dist/js/modern/compatRequire.js +5 -0
- package/dist/js/modern/constants.js +5 -19
- package/dist/js/modern/getBrowserslist.js +1 -1
- package/dist/js/modern/index.js +2 -1
- package/dist/js/modern/prettyInstructions.js +5 -4
- package/dist/js/modern/wait.js +5 -0
- package/dist/js/node/clearConsole.js +1 -1
- package/dist/js/node/compatRequire.js +10 -2
- package/dist/js/node/constants.js +7 -24
- package/dist/js/node/getBrowserslist.js +2 -2
- package/dist/js/node/index.js +14 -0
- package/dist/js/node/prettyInstructions.js +5 -4
- package/dist/js/node/wait.js +12 -0
- package/dist/js/treeshaking/clearConsole.js +1 -1
- package/dist/js/treeshaking/compatRequire.js +5 -0
- package/dist/js/treeshaking/constants.js +5 -19
- package/dist/js/treeshaking/getBrowserslist.js +1 -1
- package/dist/js/treeshaking/index.js +2 -1
- package/dist/js/treeshaking/prettyInstructions.js +6 -5
- package/dist/js/treeshaking/wait.js +8 -0
- package/dist/types/compatRequire.d.ts +2 -1
- package/dist/types/constants.d.ts +1 -16
- package/dist/types/getBrowserslist.d.ts +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/wait.d.ts +2 -0
- package/jest.config.js +8 -0
- package/package.json +20 -11
- package/tests/__snapshots__/prettyInstructions.test.ts.snap +19 -0
- package/tests/applyOptionsChain.test.ts +1 -1
- package/tests/compatRequire.test.ts +11 -1
- package/tests/debug.test.ts +4 -2
- package/tests/ensureAbsolutePath.test.ts +1 -1
- package/tests/findExists.test.ts +1 -1
- package/tests/fixtures/compat-require/foo.js +3 -0
- package/tests/getBrowserslist.test.ts +1 -1
- package/tests/getCacheIdentifier.test.ts +1 -1
- package/tests/getEntryOptions.test.ts +1 -1
- package/tests/index.test.ts +1 -1
- package/tests/logger.test.ts +1 -1
- package/tests/prettyInstructions.test.ts +139 -0
- package/tests/removeSlash.test.ts +1 -1
- package/tests/tsconfig.json +1 -3
- package/tests/wait.ts +38 -0
- package/tsconfig.json +1 -3
- package/src/FileSizeReporter.ts +0 -181
- package/src/alias.ts +0 -90
- package/src/applyOptionsChain.ts +0 -44
- package/src/chalk.ts +0 -3
- package/src/clearConsole.ts +0 -5
- package/src/compatRequire.ts +0 -25
- package/src/constants.ts +0 -262
- package/src/debug.ts +0 -8
- package/src/ensureAbsolutePath.ts +0 -10
- package/src/findExists.ts +0 -15
- package/src/formatWebpackMessages.ts +0 -131
- package/src/generateMetaTags.ts +0 -75
- package/src/getBrowserslist.ts +0 -6
- package/src/getCacheIdentifier.ts +0 -30
- package/src/getEntryOptions.ts +0 -37
- package/src/getPackageManager.ts +0 -30
- package/src/getPort.ts +0 -62
- package/src/import.ts +0 -10
- package/src/index.ts +0 -31
- package/src/is/index.ts +0 -78
- package/src/is/node-env.ts +0 -9
- package/src/is/platform.ts +0 -7
- package/src/is/type.ts +0 -43
- package/src/logger.ts +0 -184
- package/src/monorepo.ts +0 -106
- package/src/nodeEnv.ts +0 -28
- package/src/path.ts +0 -9
- package/src/pkgUp.ts +0 -3
- package/src/prettyInstructions.ts +0 -88
- package/src/printBuildError.ts +0 -47
- package/src/readTsConfig.ts +0 -21
- package/src/removeSlash.ts +0 -6
- package/src/runtimeExports.ts +0 -68
- package/src/types.d.ts +0 -1
- package/src/watch.ts +0 -56
package/src/compatRequire.ts
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
import { findExists } from './findExists';
|
2
|
-
|
3
|
-
/**
|
4
|
-
* Require function compatible with esm and cjs module.
|
5
|
-
* @param filePath - File to required.
|
6
|
-
* @returns module export object.
|
7
|
-
*/
|
8
|
-
export const compatRequire = (filePath: string) => {
|
9
|
-
const mod = require(filePath);
|
10
|
-
|
11
|
-
return mod?.__esModule ? mod.default : mod;
|
12
|
-
};
|
13
|
-
|
14
|
-
export const requireExistModule = (
|
15
|
-
filename: string,
|
16
|
-
extensions = ['.ts', '.js'],
|
17
|
-
) => {
|
18
|
-
const exist = findExists(extensions.map(ext => `${filename}${ext}`));
|
19
|
-
|
20
|
-
if (!exist) {
|
21
|
-
return null;
|
22
|
-
}
|
23
|
-
|
24
|
-
return compatRequire(exist);
|
25
|
-
};
|
package/src/constants.ts
DELETED
@@ -1,262 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* alias to src directory
|
3
|
-
*/
|
4
|
-
export const INTERNAL_SRC_ALIAS = '@_modern_js_src';
|
5
|
-
|
6
|
-
/**
|
7
|
-
* alias to node_modules/.modern-js
|
8
|
-
*/
|
9
|
-
export const INTERNAL_DIR_ALAIS = '@_modern_js_internal';
|
10
|
-
|
11
|
-
/**
|
12
|
-
* hmr socket connect path
|
13
|
-
*/
|
14
|
-
export const HMR_SOCK_PATH = '/_modern_js_hmr_ws';
|
15
|
-
|
16
|
-
/**
|
17
|
-
* route specification file
|
18
|
-
*/
|
19
|
-
export const ROUTE_SPEC_FILE = 'route.json';
|
20
|
-
|
21
|
-
/**
|
22
|
-
* main entry name
|
23
|
-
*/
|
24
|
-
export const MAIN_ENTRY_NAME = 'main';
|
25
|
-
|
26
|
-
/**
|
27
|
-
* open editor request path
|
28
|
-
*/
|
29
|
-
export const LAUNCH_EDITOR_ENDPOINT = '/__open-stack-frame-in-editor';
|
30
|
-
|
31
|
-
/**
|
32
|
-
* server side bundles directory, which relative to dist.
|
33
|
-
*/
|
34
|
-
export const SERVER_BUNDLE_DIRECTORY = 'bundles';
|
35
|
-
|
36
|
-
/**
|
37
|
-
* entry name pattern used for ajv pattern properties.
|
38
|
-
*/
|
39
|
-
export const ENTRY_NAME_PATTERN = '^[a-zA-Z0-9_-]+$';
|
40
|
-
|
41
|
-
/**
|
42
|
-
* SSR server render function name
|
43
|
-
*/
|
44
|
-
export const SERVER_RENDER_FUNCTION_NAME = 'serverRender';
|
45
|
-
|
46
|
-
/**
|
47
|
-
* loadbale manifest json file
|
48
|
-
*/
|
49
|
-
export const LOADABLE_STATS_FILE = 'loadable-stats.json';
|
50
|
-
|
51
|
-
/**
|
52
|
-
* real entry generate by modern.js
|
53
|
-
*/
|
54
|
-
export const HIDE_MODERN_JS_DIR = './node_modules/.modern-js';
|
55
|
-
|
56
|
-
/**
|
57
|
-
* internal specified folder
|
58
|
-
*/
|
59
|
-
export const API_DIR = 'api';
|
60
|
-
|
61
|
-
export const SERVER_DIR = 'server';
|
62
|
-
|
63
|
-
export const SHARED_DIR = 'shared';
|
64
|
-
|
65
|
-
/**
|
66
|
-
* Internal plugins that work as soon as they are installed.
|
67
|
-
*/
|
68
|
-
export const INTERNAL_PLUGINS: {
|
69
|
-
[name: string]: { cli?: string; server?: string };
|
70
|
-
} = {
|
71
|
-
'@modern-js/app-tools': { cli: '@modern-js/app-tools/cli' },
|
72
|
-
'@modern-js/monorepo-tools': { cli: '@modern-js/monorepo-tools/cli' },
|
73
|
-
'@modern-js/module-tools': { cli: '@modern-js/module-tools/cli' },
|
74
|
-
'@modern-js/runtime': { cli: '@modern-js/runtime/cli' },
|
75
|
-
'@modern-js/plugin-less': { cli: '@modern-js/plugin-less/cli' },
|
76
|
-
'@modern-js/plugin-sass': { cli: '@modern-js/plugin-sass/cli' },
|
77
|
-
'@modern-js/plugin-esbuild': { cli: '@modern-js/plugin-esbuild/cli' },
|
78
|
-
'@modern-js/plugin-proxy': { cli: '@modern-js/plugin-proxy/cli' },
|
79
|
-
'@modern-js/plugin-ssg': { cli: '@modern-js/plugin-ssg/cli' },
|
80
|
-
'@modern-js/plugin-bff': {
|
81
|
-
cli: '@modern-js/plugin-bff/cli',
|
82
|
-
server: '@modern-js/plugin-bff/server',
|
83
|
-
},
|
84
|
-
'@modern-js/plugin-electron': { cli: '@modern-js/plugin-electron/cli' },
|
85
|
-
'@modern-js/plugin-testing': { cli: '@modern-js/plugin-testing/cli' },
|
86
|
-
'@modern-js/plugin-storybook': { cli: '@modern-js/plugin-storybook/cli' },
|
87
|
-
'@modern-js/plugin-docsite': { cli: '@modern-js/plugin-docsite/cli' },
|
88
|
-
'@modern-js/plugin-express': {
|
89
|
-
cli: '@modern-js/plugin-express/cli',
|
90
|
-
server: '@modern-js/plugin-express',
|
91
|
-
},
|
92
|
-
'@modern-js/plugin-egg': {
|
93
|
-
cli: '@modern-js/plugin-egg/cli',
|
94
|
-
server: '@modern-js/plugin-egg',
|
95
|
-
},
|
96
|
-
'@modern-js/plugin-koa': {
|
97
|
-
cli: '@modern-js/plugin-koa/cli',
|
98
|
-
server: '@modern-js/plugin-koa',
|
99
|
-
},
|
100
|
-
'@modern-js/plugin-nest': {
|
101
|
-
cli: '@modern-js/plugin-nest/cli',
|
102
|
-
server: '@modern-js/plugin-nest/server',
|
103
|
-
},
|
104
|
-
'@modern-js/plugin-unbundle': { cli: '@modern-js/plugin-unbundle' },
|
105
|
-
'@modern-js/plugin-server-build': { cli: '@modern-js/plugin-server-build' },
|
106
|
-
'@modern-js/plugin-server': {
|
107
|
-
cli: '@modern-js/plugin-server/cli',
|
108
|
-
server: '@modern-js/plugin-server/server',
|
109
|
-
},
|
110
|
-
'@modern-js/plugin-micro-frontend': {
|
111
|
-
cli: '@modern-js/plugin-micro-frontend/cli',
|
112
|
-
},
|
113
|
-
'@modern-js/plugin-jarvis': { cli: '@modern-js/plugin-jarvis/cli' },
|
114
|
-
'@modern-js/plugin-tailwindcss': { cli: '@modern-js/plugin-tailwindcss/cli' },
|
115
|
-
'@modern-js/plugin-lambda-fc': { cli: '@modern-js/plugin-lambda-fc/cli' },
|
116
|
-
'@modern-js/plugin-lambda-scf': { cli: '@modern-js/plugin-lambda-scf/cli' },
|
117
|
-
'@modern-js/plugin-cdn-oss': { cli: '@modern-js/plugin-cdn-oss/cli' },
|
118
|
-
'@modern-js/plugin-cdn-cos': { cli: '@modern-js/plugin-cdn-cos/cli' },
|
119
|
-
'@modern-js/plugin-static-hosting': {
|
120
|
-
cli: '@modern-js/plugin-static-hosting/cli',
|
121
|
-
},
|
122
|
-
'@modern-js/plugin-polyfill': { server: '@modern-js/plugin-polyfill' },
|
123
|
-
'@modern-js/plugin-multiprocess': {
|
124
|
-
cli: '@modern-js/plugin-multiprocess/cli',
|
125
|
-
},
|
126
|
-
'@modern-js/plugin-nocode': { cli: '@modern-js/plugin-nocode/cli' },
|
127
|
-
};
|
128
|
-
|
129
|
-
/**
|
130
|
-
* The schema registered in the plugin.
|
131
|
-
*/
|
132
|
-
export const PLUGIN_SCHEMAS = {
|
133
|
-
'@modern-js/runtime': [
|
134
|
-
{
|
135
|
-
target: 'runtime',
|
136
|
-
schema: {
|
137
|
-
type: 'object',
|
138
|
-
additionalProperties: false,
|
139
|
-
},
|
140
|
-
},
|
141
|
-
{
|
142
|
-
target: 'runtimeByEntries',
|
143
|
-
schema: {
|
144
|
-
type: 'object',
|
145
|
-
patternProperties: { [ENTRY_NAME_PATTERN]: { type: 'object' } },
|
146
|
-
additionalProperties: false,
|
147
|
-
},
|
148
|
-
},
|
149
|
-
],
|
150
|
-
'@modern-js/plugin-bff': [
|
151
|
-
{
|
152
|
-
target: 'bff',
|
153
|
-
schema: {
|
154
|
-
type: 'object',
|
155
|
-
properties: {
|
156
|
-
prefix: {
|
157
|
-
type: ['string', 'array'],
|
158
|
-
items: { type: 'string' },
|
159
|
-
},
|
160
|
-
fetcher: { type: 'string' },
|
161
|
-
proxy: { type: 'object' },
|
162
|
-
requestCreator: { type: 'string' },
|
163
|
-
},
|
164
|
-
},
|
165
|
-
},
|
166
|
-
],
|
167
|
-
'@modern-js/plugin-esbuild': [
|
168
|
-
{
|
169
|
-
target: 'tools.esbuild',
|
170
|
-
schema: { typeof: ['object'] },
|
171
|
-
},
|
172
|
-
],
|
173
|
-
'@modern-js/plugin-less': [
|
174
|
-
{
|
175
|
-
target: 'tools.less',
|
176
|
-
schema: { typeof: ['object', 'function'] },
|
177
|
-
},
|
178
|
-
],
|
179
|
-
'@modern-js/plugin-sass': [
|
180
|
-
{
|
181
|
-
target: 'tools.sass',
|
182
|
-
schema: { typeof: ['object', 'function'] },
|
183
|
-
},
|
184
|
-
],
|
185
|
-
'@modern-js/plugin-tailwindcss': [
|
186
|
-
{
|
187
|
-
target: 'tools.tailwindcss',
|
188
|
-
schema: { typeof: ['object', 'function'] },
|
189
|
-
},
|
190
|
-
{
|
191
|
-
target: 'source.designSystem',
|
192
|
-
schema: { typeof: ['object'] },
|
193
|
-
},
|
194
|
-
],
|
195
|
-
'@modern-js/plugin-proxy': [
|
196
|
-
{
|
197
|
-
target: 'dev.proxy',
|
198
|
-
schema: { typeof: ['string', 'object'] },
|
199
|
-
},
|
200
|
-
],
|
201
|
-
'@modern-js/plugin-unbundle': [
|
202
|
-
{
|
203
|
-
target: 'source.disableAutoImportStyle',
|
204
|
-
schema: { type: 'boolean' },
|
205
|
-
},
|
206
|
-
{
|
207
|
-
target: 'server.https',
|
208
|
-
schema: { type: 'boolean' },
|
209
|
-
},
|
210
|
-
],
|
211
|
-
'@modern-js/plugin-ssg': [
|
212
|
-
{
|
213
|
-
target: 'output.ssg',
|
214
|
-
schema: {
|
215
|
-
oneOf: [
|
216
|
-
{ type: 'boolean' },
|
217
|
-
{ type: 'object' },
|
218
|
-
{ instanceof: 'Function' },
|
219
|
-
],
|
220
|
-
},
|
221
|
-
},
|
222
|
-
],
|
223
|
-
'@modern-js/plugin-ssr': [
|
224
|
-
{
|
225
|
-
target: 'runtime.ssr',
|
226
|
-
schema: { type: ['boolean', 'object'] },
|
227
|
-
},
|
228
|
-
],
|
229
|
-
'@modern-js/plugin-state': [
|
230
|
-
{
|
231
|
-
target: 'runtime.state',
|
232
|
-
schema: { type: ['boolean', 'object'] },
|
233
|
-
},
|
234
|
-
],
|
235
|
-
'@modern-js/plugin-router': [
|
236
|
-
{
|
237
|
-
target: 'runtime.router',
|
238
|
-
schema: { type: ['boolean', 'object'] },
|
239
|
-
},
|
240
|
-
],
|
241
|
-
'@modern-js/plugin-testing': [
|
242
|
-
{
|
243
|
-
target: 'testing',
|
244
|
-
schema: { typeof: ['object'] },
|
245
|
-
},
|
246
|
-
{
|
247
|
-
target: 'tools.jest',
|
248
|
-
schema: { typeof: ['object'] },
|
249
|
-
},
|
250
|
-
],
|
251
|
-
'@modern-js/plugin-micro-frontend': [
|
252
|
-
{
|
253
|
-
target: 'runtime.masterApp',
|
254
|
-
schema: { type: ['object'] },
|
255
|
-
},
|
256
|
-
{
|
257
|
-
target: 'dev.withMasterApp',
|
258
|
-
schema: { type: ['object'] },
|
259
|
-
},
|
260
|
-
],
|
261
|
-
'@modern-js/plugin-nocode': [],
|
262
|
-
};
|
package/src/debug.ts
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
import debug from 'debug';
|
2
|
-
|
3
|
-
/**
|
4
|
-
* Create debug function with unified namespace prefix.
|
5
|
-
* @param scope - Custom module name of your debug function.
|
6
|
-
* @returns Debug function which namespace start with modern-js:.
|
7
|
-
*/
|
8
|
-
export const createDebugger = (scope: string) => debug(`modern-js:${scope}`);
|
@@ -1,10 +0,0 @@
|
|
1
|
-
import path from 'path';
|
2
|
-
|
3
|
-
/**
|
4
|
-
* ensure absolute file path.
|
5
|
-
* @param base - Base path to resolve relative from.
|
6
|
-
* @param filePath - Aboluste or relative file path.
|
7
|
-
* @returns Resolved absolute file path.
|
8
|
-
*/
|
9
|
-
export const ensureAbsolutePath = (base: string, filePath: string): string =>
|
10
|
-
path.isAbsolute(filePath) ? filePath : path.resolve(base, filePath);
|
package/src/findExists.ts
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
import fs from 'fs';
|
2
|
-
|
3
|
-
/**
|
4
|
-
* Find first already exists file.
|
5
|
-
* @param files - Asbolute file paths with extension.
|
6
|
-
* @returns The file path if exists, or false if no file exists.
|
7
|
-
*/
|
8
|
-
export const findExists = (files: string[]): string | false => {
|
9
|
-
for (const file of files) {
|
10
|
-
if (fs.existsSync(file) && fs.statSync(file).isFile()) {
|
11
|
-
return file;
|
12
|
-
}
|
13
|
-
}
|
14
|
-
return false;
|
15
|
-
};
|
@@ -1,131 +0,0 @@
|
|
1
|
-
/* eslint-disable no-param-reassign */
|
2
|
-
/* eslint-disable max-statements */
|
3
|
-
/**
|
4
|
-
* Copyright (c) 2015-present, Facebook, Inc.
|
5
|
-
*
|
6
|
-
* This source code is licensed under the MIT license found in the
|
7
|
-
* LICENSE file at
|
8
|
-
* https://github.com/facebook/create-react-app/blob/master/LICENSE
|
9
|
-
*/
|
10
|
-
|
11
|
-
// Modified by Chao Xu (xuchaobei)
|
12
|
-
|
13
|
-
import webpack, { StatsCompilation } from 'webpack';
|
14
|
-
|
15
|
-
const friendlySyntaxErrorLabel = 'Syntax error:';
|
16
|
-
|
17
|
-
function isLikelyASyntaxError(message: string) {
|
18
|
-
return message.includes(friendlySyntaxErrorLabel);
|
19
|
-
}
|
20
|
-
|
21
|
-
// Cleans up webpack error messages.
|
22
|
-
function formatMessage(message: webpack.StatsError | string) {
|
23
|
-
let lines: string[] = [];
|
24
|
-
|
25
|
-
// webpack 5 stats error object
|
26
|
-
if (typeof message === 'object') {
|
27
|
-
message = `${(message.moduleName && `${message.moduleName}\n`) as string}${
|
28
|
-
message.details || message.stack || message.message
|
29
|
-
}`;
|
30
|
-
}
|
31
|
-
|
32
|
-
lines = message.split('\n');
|
33
|
-
|
34
|
-
// Strip webpack-added headers off errors/warnings
|
35
|
-
// https://github.com/webpack/webpack/blob/master/lib/ModuleError.js
|
36
|
-
lines = lines.filter(line => !/Module [A-z ]+\(from/.test(line));
|
37
|
-
|
38
|
-
// Transform parsing error into syntax error
|
39
|
-
lines = lines.map(line => {
|
40
|
-
const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(
|
41
|
-
line,
|
42
|
-
);
|
43
|
-
if (!parsingError) {
|
44
|
-
return line;
|
45
|
-
}
|
46
|
-
const [, errorLine, errorColumn, errorMessage] = parsingError;
|
47
|
-
return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
|
48
|
-
});
|
49
|
-
|
50
|
-
message = lines.join('\n');
|
51
|
-
|
52
|
-
// Smoosh syntax errors (commonly found in CSS)
|
53
|
-
message = message.replace(
|
54
|
-
/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g,
|
55
|
-
`${friendlySyntaxErrorLabel} $3 ($1:$2)\n`,
|
56
|
-
);
|
57
|
-
|
58
|
-
lines = message.split('\n');
|
59
|
-
|
60
|
-
// Remove leading newline
|
61
|
-
if (lines.length > 2 && lines[1].trim() === '') {
|
62
|
-
lines.splice(1, 1);
|
63
|
-
}
|
64
|
-
// Clean up file name
|
65
|
-
lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, '$1');
|
66
|
-
|
67
|
-
// Cleans up verbose "module not found" messages for files and packages.
|
68
|
-
if (lines[1]?.startsWith('Module not found: ')) {
|
69
|
-
lines = [
|
70
|
-
lines[0],
|
71
|
-
lines[1]
|
72
|
-
.replace('Error: ', '')
|
73
|
-
.replace('Module not found: Cannot find file:', 'Cannot find file:')
|
74
|
-
.replace('[CaseSensitivePathsPlugin] ', '')
|
75
|
-
.replace("Cannot resolve 'file' or 'directory' ", ''),
|
76
|
-
];
|
77
|
-
}
|
78
|
-
|
79
|
-
message = lines.join('\n');
|
80
|
-
// Internal stacks are generally useless so we strip them... with the
|
81
|
-
// exception of stacks containing `webpack:` because they're normally
|
82
|
-
// from user code generated by webpack. For more information see
|
83
|
-
// https://github.com/facebook/create-react-app/pull/1050
|
84
|
-
message = message.replace(
|
85
|
-
/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm,
|
86
|
-
'',
|
87
|
-
); // at ... ...:x:y
|
88
|
-
message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, ''); // at <anonymous>
|
89
|
-
lines = message.split('\n');
|
90
|
-
|
91
|
-
// Remove duplicated newlines
|
92
|
-
lines = lines.filter(
|
93
|
-
(line, index, arr) =>
|
94
|
-
index === 0 ||
|
95
|
-
line.trim() !== '' ||
|
96
|
-
line.trim() !== arr[index - 1].trim(),
|
97
|
-
);
|
98
|
-
|
99
|
-
// Reassemble the message
|
100
|
-
message = lines.join('\n');
|
101
|
-
return message.trim();
|
102
|
-
}
|
103
|
-
|
104
|
-
function formatWebpackMessages(json: StatsCompilation): {
|
105
|
-
errors: string[];
|
106
|
-
warnings: string[];
|
107
|
-
} {
|
108
|
-
const formattedErrors = json.errors?.map(formatMessage);
|
109
|
-
const formattedWarnings = json.warnings?.map(formatMessage);
|
110
|
-
|
111
|
-
const result = {
|
112
|
-
errors: formattedErrors || [],
|
113
|
-
warnings: formattedWarnings || [],
|
114
|
-
};
|
115
|
-
|
116
|
-
if (result.errors?.some(isLikelyASyntaxError)) {
|
117
|
-
// If there are any syntax errors, show just them.
|
118
|
-
result.errors = result.errors.filter(isLikelyASyntaxError);
|
119
|
-
}
|
120
|
-
|
121
|
-
// First error is usually it.
|
122
|
-
if (result.errors.length > 1) {
|
123
|
-
result.errors.length = 1;
|
124
|
-
}
|
125
|
-
|
126
|
-
return result;
|
127
|
-
}
|
128
|
-
|
129
|
-
export { formatWebpackMessages };
|
130
|
-
/* eslint-enable max-statements */
|
131
|
-
/* eslint-enable no-param-reassign */
|
package/src/generateMetaTags.ts
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright JS Foundation and other contributors.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file at
|
6
|
-
* https://github.com/jantimon/html-webpack-plugin/blob/main/LICENSE
|
7
|
-
*
|
8
|
-
* Modified from https://github.com/jantimon/html-webpack-plugin/blob/2f5de7ab9e8bca60e9e200f2e4b4cfab90db28d4/index.js#L800
|
9
|
-
*/
|
10
|
-
export type MetaAttributes = { [attributeName: string]: string | boolean };
|
11
|
-
|
12
|
-
export interface MetaOptions {
|
13
|
-
[name: string]:
|
14
|
-
| string
|
15
|
-
| false // name content pair e.g. {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'}`
|
16
|
-
| MetaAttributes; // custom properties e.g. { name:"viewport" content:"width=500, initial-scale=1" }
|
17
|
-
}
|
18
|
-
|
19
|
-
const tagObjectToString = (tagDefinition: {
|
20
|
-
tagName: string;
|
21
|
-
voidTag: boolean;
|
22
|
-
attributes: MetaAttributes;
|
23
|
-
innerHTML?: string;
|
24
|
-
}) => {
|
25
|
-
const attributes = Object.keys(tagDefinition.attributes || {})
|
26
|
-
.filter(attributeName => tagDefinition.attributes[attributeName] !== false)
|
27
|
-
.map(attributeName => {
|
28
|
-
if (tagDefinition.attributes[attributeName] === true) {
|
29
|
-
return attributeName;
|
30
|
-
}
|
31
|
-
return `${attributeName}="${
|
32
|
-
tagDefinition.attributes[attributeName] as string
|
33
|
-
}"`;
|
34
|
-
});
|
35
|
-
return `<${[tagDefinition.tagName].concat(attributes).join(' ')}>${
|
36
|
-
tagDefinition.innerHTML || ''
|
37
|
-
}${tagDefinition.voidTag ? '' : `</${tagDefinition.tagName}>`}`;
|
38
|
-
};
|
39
|
-
|
40
|
-
export const generateMetaTags = (metaOptions?: MetaOptions): string => {
|
41
|
-
if (!metaOptions) {
|
42
|
-
return '';
|
43
|
-
}
|
44
|
-
// Make tags self-closing in case of xhtml
|
45
|
-
// Turn { "viewport" : "width=500, initial-scale=1" } into
|
46
|
-
// [{ name:"viewport" content:"width=500, initial-scale=1" }]
|
47
|
-
const metaTagAttributeObjects = Object.keys(metaOptions)
|
48
|
-
.map(metaName => {
|
49
|
-
const metaTagContent = metaOptions[metaName];
|
50
|
-
return typeof metaTagContent === 'string'
|
51
|
-
? {
|
52
|
-
name: metaName,
|
53
|
-
content: metaTagContent,
|
54
|
-
}
|
55
|
-
: metaTagContent;
|
56
|
-
})
|
57
|
-
.filter(attribute => attribute !== false);
|
58
|
-
// Turn [{ name:"viewport" content:"width=500, initial-scale=1" }] into
|
59
|
-
// the html-webpack-plugin tag structure
|
60
|
-
return metaTagAttributeObjects
|
61
|
-
.map(metaTagAttributes => {
|
62
|
-
if (metaTagAttributes === false) {
|
63
|
-
throw new Error('Invalid meta tag');
|
64
|
-
}
|
65
|
-
return {
|
66
|
-
tagName: 'meta',
|
67
|
-
voidTag: true,
|
68
|
-
attributes: metaTagAttributes,
|
69
|
-
};
|
70
|
-
})
|
71
|
-
.reduce(
|
72
|
-
(memo, tagObject) => `${memo}\n${tagObjectToString(tagObject)}`,
|
73
|
-
'',
|
74
|
-
);
|
75
|
-
};
|
package/src/getBrowserslist.ts
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
import { isProd, isDev, isTest } from './is';
|
2
|
-
|
3
|
-
/**
|
4
|
-
* Generate cache identifier from some packages and config files.
|
5
|
-
*/
|
6
|
-
export function getCacheIdentifier(
|
7
|
-
packages: {
|
8
|
-
name: string;
|
9
|
-
version: string;
|
10
|
-
}[],
|
11
|
-
_files?: string[],
|
12
|
-
) {
|
13
|
-
/* eslint-disable no-nested-ternary */
|
14
|
-
let cacheIdentifier = isProd()
|
15
|
-
? 'production'
|
16
|
-
: isDev()
|
17
|
-
? 'development'
|
18
|
-
: isTest()
|
19
|
-
? 'test'
|
20
|
-
: '';
|
21
|
-
/* eslint-enable no-nested-ternary */
|
22
|
-
|
23
|
-
for (const { name, version } of packages) {
|
24
|
-
cacheIdentifier += `:${name}@${version}`;
|
25
|
-
}
|
26
|
-
|
27
|
-
// TODO: config file hash
|
28
|
-
|
29
|
-
return cacheIdentifier;
|
30
|
-
}
|
package/src/getEntryOptions.ts
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
import { isPlainObject } from './is';
|
2
|
-
import { MAIN_ENTRY_NAME } from './constants';
|
3
|
-
|
4
|
-
export const getEntryOptions = <T>(
|
5
|
-
name: string,
|
6
|
-
baseOptions?: T,
|
7
|
-
optionsByEntries?: Record<string, T>,
|
8
|
-
packageName?: string,
|
9
|
-
) => {
|
10
|
-
if (optionsByEntries) {
|
11
|
-
let optionsByEntry = getOptionsByEntryName(name, optionsByEntries);
|
12
|
-
|
13
|
-
// compatible with main entry using packageName as the key
|
14
|
-
if (
|
15
|
-
optionsByEntry === undefined &&
|
16
|
-
name === MAIN_ENTRY_NAME &&
|
17
|
-
packageName
|
18
|
-
) {
|
19
|
-
optionsByEntry = getOptionsByEntryName(packageName, optionsByEntries);
|
20
|
-
}
|
21
|
-
|
22
|
-
// eslint-disable-next-line no-nested-ternary
|
23
|
-
return optionsByEntry !== undefined
|
24
|
-
? isPlainObject(optionsByEntry) && isPlainObject(baseOptions)
|
25
|
-
? { ...baseOptions, ...optionsByEntry }
|
26
|
-
: optionsByEntry
|
27
|
-
: baseOptions;
|
28
|
-
} else {
|
29
|
-
return baseOptions;
|
30
|
-
}
|
31
|
-
};
|
32
|
-
|
33
|
-
const getOptionsByEntryName = <T>(
|
34
|
-
name: string,
|
35
|
-
optionsByEntries: Record<string, T>,
|
36
|
-
) =>
|
37
|
-
optionsByEntries.hasOwnProperty(name) ? optionsByEntries[name] : undefined;
|
package/src/getPackageManager.ts
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
import os from 'os';
|
2
|
-
import path from 'path';
|
3
|
-
import fs from 'fs-extra';
|
4
|
-
import { canUsePnpm, canUseYarn } from './nodeEnv';
|
5
|
-
|
6
|
-
const MAX_TIMES = 5;
|
7
|
-
export async function getPackageManager(cwd: string = process.cwd()) {
|
8
|
-
let appDirectory = cwd;
|
9
|
-
let times = 0;
|
10
|
-
while (os.homedir() !== appDirectory && times < MAX_TIMES) {
|
11
|
-
times++;
|
12
|
-
if (fs.existsSync(path.resolve(appDirectory, 'pnpm-lock.yaml'))) {
|
13
|
-
return 'pnpm';
|
14
|
-
}
|
15
|
-
if (fs.existsSync(path.resolve(appDirectory, 'yarn.lock'))) {
|
16
|
-
return 'yarn';
|
17
|
-
}
|
18
|
-
if (fs.existsSync(path.resolve(appDirectory, 'package-lock.json'))) {
|
19
|
-
return 'npm';
|
20
|
-
}
|
21
|
-
appDirectory = path.join(appDirectory, '..');
|
22
|
-
}
|
23
|
-
if (await canUsePnpm()) {
|
24
|
-
return 'pnpm';
|
25
|
-
}
|
26
|
-
if (await canUseYarn()) {
|
27
|
-
return 'yarn';
|
28
|
-
}
|
29
|
-
return 'npm';
|
30
|
-
}
|