@modern-js/app-tools 2.54.1-alpha.2 → 2.54.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/commands/build.js +1 -1
- package/dist/cjs/commands/deploy.js +2 -1
- package/dist/cjs/commands/dev.js +1 -1
- package/dist/cjs/commands/serve.js +1 -1
- package/dist/cjs/plugins/deploy/dependencies/index.js +17 -26
- package/dist/cjs/plugins/deploy/dependencies/utils.js +20 -14
- package/dist/cjs/plugins/deploy/platforms/netlify.js +3 -7
- package/dist/cjs/plugins/deploy/platforms/node.js +3 -8
- package/dist/cjs/plugins/deploy/platforms/vercel.js +3 -7
- package/dist/cjs/utils/loadPlugins.js +6 -5
- package/dist/esm/commands/build.js +1 -1
- package/dist/esm/commands/deploy.js +3 -2
- package/dist/esm/commands/dev.js +1 -1
- package/dist/esm/commands/serve.js +1 -1
- package/dist/esm/plugins/deploy/dependencies/index.js +69 -94
- package/dist/esm/plugins/deploy/dependencies/utils.js +39 -19
- package/dist/esm/plugins/deploy/platforms/netlify.js +3 -7
- package/dist/esm/plugins/deploy/platforms/node.js +3 -8
- package/dist/esm/plugins/deploy/platforms/vercel.js +3 -7
- package/dist/esm/utils/loadPlugins.js +11 -6
- package/dist/esm-node/commands/build.js +1 -1
- package/dist/esm-node/commands/deploy.js +2 -1
- package/dist/esm-node/commands/dev.js +1 -1
- package/dist/esm-node/commands/serve.js +1 -1
- package/dist/esm-node/plugins/deploy/dependencies/index.js +18 -27
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +21 -15
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +3 -7
- package/dist/esm-node/plugins/deploy/platforms/node.js +3 -8
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +3 -7
- package/dist/esm-node/utils/loadPlugins.js +6 -5
- package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -11
- package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -7
- package/dist/types/utils/loadPlugins.d.ts +2 -2
- package/package.json +17 -25
- package/dist/cjs/plugins/deploy/exports.js +0 -28
- package/dist/esm/plugins/deploy/exports.js +0 -4
- package/dist/esm-node/plugins/deploy/exports.js +0 -4
- package/dist/js/modern/analyze/constants.js +0 -15
- package/dist/js/modern/analyze/generateCode.js +0 -179
- package/dist/js/modern/analyze/getBundleEntry.js +0 -75
- package/dist/js/modern/analyze/getClientRoutes.js +0 -219
- package/dist/js/modern/analyze/getFileSystemEntry.js +0 -74
- package/dist/js/modern/analyze/getHtmlTemplate.js +0 -82
- package/dist/js/modern/analyze/getServerRoutes.js +0 -192
- package/dist/js/modern/analyze/index.js +0 -148
- package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -32
- package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -16
- package/dist/js/modern/analyze/templates.js +0 -88
- package/dist/js/modern/analyze/utils.js +0 -92
- package/dist/js/modern/commands/build.js +0 -154
- package/dist/js/modern/commands/deploy.js +0 -5
- package/dist/js/modern/commands/dev.js +0 -95
- package/dist/js/modern/commands/index.js +0 -3
- package/dist/js/modern/commands/inspect.js +0 -69
- package/dist/js/modern/commands/start.js +0 -31
- package/dist/js/modern/exports/server.js +0 -1
- package/dist/js/modern/hooks.js +0 -21
- package/dist/js/modern/index.js +0 -109
- package/dist/js/modern/locale/en.js +0 -35
- package/dist/js/modern/locale/index.js +0 -9
- package/dist/js/modern/locale/zh.js +0 -35
- package/dist/js/modern/utils/config.js +0 -78
- package/dist/js/modern/utils/createCompiler.js +0 -61
- package/dist/js/modern/utils/createServer.js +0 -18
- package/dist/js/modern/utils/getSpecifiedEntries.js +0 -36
- package/dist/js/modern/utils/language.js +0 -5
- package/dist/js/modern/utils/printInstructions.js +0 -11
- package/dist/js/modern/utils/routes.js +0 -15
- package/dist/js/modern/utils/types.js +0 -0
- package/dist/js/node/analyze/constants.js +0 -36
- package/dist/js/node/analyze/generateCode.js +0 -208
- package/dist/js/node/analyze/getBundleEntry.js +0 -89
- package/dist/js/node/analyze/getClientRoutes.js +0 -241
- package/dist/js/node/analyze/getFileSystemEntry.js +0 -90
- package/dist/js/node/analyze/getHtmlTemplate.js +0 -106
- package/dist/js/node/analyze/getServerRoutes.js +0 -208
- package/dist/js/node/analyze/index.js +0 -178
- package/dist/js/node/analyze/isDefaultExportFunction.js +0 -50
- package/dist/js/node/analyze/makeLegalIdentifier.js +0 -24
- package/dist/js/node/analyze/templates.js +0 -106
- package/dist/js/node/analyze/utils.js +0 -113
- package/dist/js/node/commands/build.js +0 -174
- package/dist/js/node/commands/deploy.js +0 -14
- package/dist/js/node/commands/dev.js +0 -120
- package/dist/js/node/commands/index.js +0 -44
- package/dist/js/node/commands/inspect.js +0 -98
- package/dist/js/node/commands/start.js +0 -47
- package/dist/js/node/exports/server.js +0 -13
- package/dist/js/node/hooks.js +0 -39
- package/dist/js/node/index.js +0 -141
- package/dist/js/node/locale/en.js +0 -42
- package/dist/js/node/locale/index.js +0 -20
- package/dist/js/node/locale/zh.js +0 -42
- package/dist/js/node/utils/config.js +0 -103
- package/dist/js/node/utils/createCompiler.js +0 -81
- package/dist/js/node/utils/createServer.js +0 -35
- package/dist/js/node/utils/getSpecifiedEntries.js +0 -46
- package/dist/js/node/utils/language.js +0 -13
- package/dist/js/node/utils/printInstructions.js +0 -22
- package/dist/js/node/utils/routes.js +0 -25
- package/dist/js/node/utils/types.js +0 -0
- package/dist/types/plugins/deploy/exports.d.ts +0 -1
@@ -1,178 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.modifyServerRoutes = exports.modifyFileSystemRoutes = exports.modifyEntryRuntimePlugins = exports.modifyEntryRenderFunction = exports.modifyEntryImports = exports.modifyEntryExport = exports.modifyAsyncEntry = exports.htmlPartials = exports.default = exports.beforeGenerateRoutes = exports.addRuntimeExports = exports.addDefineTypes = void 0;
|
7
|
-
|
8
|
-
var path = _interopRequireWildcard(require("path"));
|
9
|
-
|
10
|
-
var _plugin = require("@modern-js/plugin");
|
11
|
-
|
12
|
-
var _utils = require("@modern-js/utils");
|
13
|
-
|
14
|
-
var _lodash = require("@modern-js/utils/lodash");
|
15
|
-
|
16
|
-
var _utils2 = require("./utils");
|
17
|
-
|
18
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
19
|
-
|
20
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
21
|
-
|
22
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
23
|
-
|
24
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
25
|
-
|
26
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
27
|
-
|
28
|
-
const debug = (0, _utils.createDebugger)('plugin-analyze');
|
29
|
-
const modifyEntryImports = (0, _plugin.createAsyncWaterfall)();
|
30
|
-
exports.modifyEntryImports = modifyEntryImports;
|
31
|
-
const modifyEntryExport = (0, _plugin.createAsyncWaterfall)();
|
32
|
-
exports.modifyEntryExport = modifyEntryExport;
|
33
|
-
const addRuntimeExports = (0, _plugin.createAsyncWaterfall)();
|
34
|
-
exports.addRuntimeExports = addRuntimeExports;
|
35
|
-
const modifyEntryRuntimePlugins = (0, _plugin.createAsyncWaterfall)();
|
36
|
-
exports.modifyEntryRuntimePlugins = modifyEntryRuntimePlugins;
|
37
|
-
const modifyEntryRenderFunction = (0, _plugin.createAsyncWaterfall)();
|
38
|
-
exports.modifyEntryRenderFunction = modifyEntryRenderFunction;
|
39
|
-
const modifyAsyncEntry = (0, _plugin.createAsyncWaterfall)();
|
40
|
-
exports.modifyAsyncEntry = modifyAsyncEntry;
|
41
|
-
const modifyFileSystemRoutes = (0, _plugin.createAsyncWaterfall)();
|
42
|
-
exports.modifyFileSystemRoutes = modifyFileSystemRoutes;
|
43
|
-
const modifyServerRoutes = (0, _plugin.createAsyncWaterfall)();
|
44
|
-
exports.modifyServerRoutes = modifyServerRoutes;
|
45
|
-
const htmlPartials = (0, _plugin.createAsyncWaterfall)();
|
46
|
-
exports.htmlPartials = htmlPartials;
|
47
|
-
const beforeGenerateRoutes = (0, _plugin.createAsyncWaterfall)();
|
48
|
-
exports.beforeGenerateRoutes = beforeGenerateRoutes;
|
49
|
-
const addDefineTypes = (0, _plugin.createAsyncWaterfall)();
|
50
|
-
exports.addDefineTypes = addDefineTypes;
|
51
|
-
|
52
|
-
var _default = () => ({
|
53
|
-
name: '@modern-js/plugin-analyze',
|
54
|
-
registerHook: {
|
55
|
-
modifyAsyncEntry,
|
56
|
-
modifyEntryImports,
|
57
|
-
modifyEntryExport,
|
58
|
-
modifyEntryRuntimePlugins,
|
59
|
-
modifyEntryRenderFunction,
|
60
|
-
modifyFileSystemRoutes,
|
61
|
-
modifyServerRoutes,
|
62
|
-
htmlPartials,
|
63
|
-
addRuntimeExports,
|
64
|
-
beforeGenerateRoutes,
|
65
|
-
addDefineTypes
|
66
|
-
},
|
67
|
-
setup: api => {
|
68
|
-
let pagesDir = [];
|
69
|
-
let originEntrypoints = [];
|
70
|
-
return {
|
71
|
-
async prepare() {
|
72
|
-
var _resolvedConfig$sourc;
|
73
|
-
|
74
|
-
const appContext = api.useAppContext();
|
75
|
-
const resolvedConfig = api.useResolvedConfigContext();
|
76
|
-
const hookRunners = api.useHookRunners();
|
77
|
-
|
78
|
-
try {
|
79
|
-
_utils.fs.emptydirSync(appContext.internalDirectory);
|
80
|
-
} catch (_unused) {// FIXME:
|
81
|
-
}
|
82
|
-
|
83
|
-
const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$sourc = resolvedConfig.source) === null || _resolvedConfig$sourc === void 0 ? void 0 : _resolvedConfig$sourc.entriesDir);
|
84
|
-
await hookRunners.addRuntimeExports();
|
85
|
-
|
86
|
-
if (apiOnly) {
|
87
|
-
const {
|
88
|
-
routes
|
89
|
-
} = await hookRunners.modifyServerRoutes({
|
90
|
-
routes: []
|
91
|
-
});
|
92
|
-
debug(`server routes: %o`, routes);
|
93
|
-
api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
|
94
|
-
apiOnly,
|
95
|
-
serverRoutes: routes
|
96
|
-
}));
|
97
|
-
return;
|
98
|
-
}
|
99
|
-
|
100
|
-
const [{
|
101
|
-
getBundleEntry
|
102
|
-
}, {
|
103
|
-
getServerRoutes
|
104
|
-
}, {
|
105
|
-
generateCode
|
106
|
-
}, {
|
107
|
-
getHtmlTemplate
|
108
|
-
}] = await Promise.all([Promise.resolve().then(() => _interopRequireWildcard(require("./getBundleEntry"))), Promise.resolve().then(() => _interopRequireWildcard(require("./getServerRoutes"))), Promise.resolve().then(() => _interopRequireWildcard(require("./generateCode"))), Promise.resolve().then(() => _interopRequireWildcard(require("./getHtmlTemplate")))]);
|
109
|
-
const entrypoints = getBundleEntry(appContext, resolvedConfig);
|
110
|
-
const defaultChecked = entrypoints.map(point => point.entryName);
|
111
|
-
debug(`entrypoints: %o`, entrypoints);
|
112
|
-
const initialRoutes = getServerRoutes(entrypoints, {
|
113
|
-
appContext,
|
114
|
-
config: resolvedConfig
|
115
|
-
});
|
116
|
-
const {
|
117
|
-
routes
|
118
|
-
} = await hookRunners.modifyServerRoutes({
|
119
|
-
routes: initialRoutes
|
120
|
-
});
|
121
|
-
debug(`server routes: %o`, routes);
|
122
|
-
api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
|
123
|
-
entrypoints,
|
124
|
-
serverRoutes: routes
|
125
|
-
}));
|
126
|
-
pagesDir = entrypoints.map(point => point.entry);
|
127
|
-
originEntrypoints = (0, _lodash.cloneDeep)(entrypoints);
|
128
|
-
await generateCode(appContext, resolvedConfig, entrypoints, api);
|
129
|
-
const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
|
130
|
-
appContext,
|
131
|
-
config: resolvedConfig
|
132
|
-
});
|
133
|
-
debug(`html templates: %o`, htmlTemplates);
|
134
|
-
await hookRunners.addDefineTypes();
|
135
|
-
debug(`add Define Types`);
|
136
|
-
api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
|
137
|
-
entrypoints,
|
138
|
-
checkedEntries: defaultChecked,
|
139
|
-
apiOnly,
|
140
|
-
serverRoutes: routes,
|
141
|
-
htmlTemplates
|
142
|
-
}));
|
143
|
-
},
|
144
|
-
|
145
|
-
watchFiles() {
|
146
|
-
return pagesDir;
|
147
|
-
},
|
148
|
-
|
149
|
-
async fileChange(e) {
|
150
|
-
const appContext = api.useAppContext();
|
151
|
-
const {
|
152
|
-
appDirectory
|
153
|
-
} = appContext;
|
154
|
-
const {
|
155
|
-
filename,
|
156
|
-
eventType
|
157
|
-
} = e;
|
158
|
-
|
159
|
-
const isPageFile = name => pagesDir.some(pageDir => name.includes(pageDir));
|
160
|
-
|
161
|
-
const absoluteFilePath = path.resolve(appDirectory, filename);
|
162
|
-
const isRouteComponent = isPageFile(absoluteFilePath) && (0, _utils2.isRouteComponentFile)(absoluteFilePath);
|
163
|
-
|
164
|
-
if (isRouteComponent && (eventType === 'add' || eventType === 'unlink')) {
|
165
|
-
const resolvedConfig = api.useResolvedConfigContext();
|
166
|
-
const {
|
167
|
-
generateCode
|
168
|
-
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./generateCode")));
|
169
|
-
const entrypoints = (0, _lodash.cloneDeep)(originEntrypoints);
|
170
|
-
generateCode(appContext, resolvedConfig, entrypoints, api);
|
171
|
-
}
|
172
|
-
}
|
173
|
-
|
174
|
-
};
|
175
|
-
}
|
176
|
-
});
|
177
|
-
|
178
|
-
exports.default = _default;
|
@@ -1,50 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.isDefaultExportFunction = void 0;
|
7
|
-
|
8
|
-
var _fs = _interopRequireDefault(require("fs"));
|
9
|
-
|
10
|
-
var _parser = require("@babel/parser");
|
11
|
-
|
12
|
-
var _traverse = _interopRequireDefault(require("@babel/traverse"));
|
13
|
-
|
14
|
-
var t = _interopRequireWildcard(require("@babel/types"));
|
15
|
-
|
16
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
17
|
-
|
18
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
19
|
-
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
21
|
-
|
22
|
-
const isFunction = node => t.isFunctionDeclaration(node) || t.isFunctionExpression(node) || t.isArrowFunctionExpression(node);
|
23
|
-
|
24
|
-
const isDefaultExportFunction = file => {
|
25
|
-
if (!file || !_fs.default.existsSync(file)) {
|
26
|
-
return false;
|
27
|
-
}
|
28
|
-
|
29
|
-
const ast = (0, _parser.parse)(_fs.default.readFileSync(file, 'utf8'), {
|
30
|
-
sourceType: 'unambiguous',
|
31
|
-
plugins: ['jsx', 'typescript', 'classProperties', 'dynamicImport', 'exportDefaultFrom', 'exportNamespaceFrom', 'decorators-legacy', 'functionBind', 'classPrivateMethods', ['pipelineOperator', {
|
32
|
-
proposal: 'minimal'
|
33
|
-
}], 'optionalChaining', 'optionalCatchBinding', 'objectRestSpread', 'numericSeparator']
|
34
|
-
});
|
35
|
-
let isExportFunction = false;
|
36
|
-
(0, _traverse.default)(ast, {
|
37
|
-
ExportDefaultDeclaration: path => {
|
38
|
-
const {
|
39
|
-
declaration
|
40
|
-
} = path.node;
|
41
|
-
|
42
|
-
if (isFunction(declaration)) {
|
43
|
-
isExportFunction = true;
|
44
|
-
}
|
45
|
-
}
|
46
|
-
});
|
47
|
-
return isExportFunction;
|
48
|
-
};
|
49
|
-
|
50
|
-
exports.isDefaultExportFunction = isDefaultExportFunction;
|
@@ -1,24 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.makeLegalIdentifier = makeLegalIdentifier;
|
7
|
-
|
8
|
-
/**
|
9
|
-
* modified from https://github.com/rollup/plugins/blob/master/packages/pluginutils
|
10
|
-
* license at https://github.com/rollup/plugins/blob/master/LICENSE
|
11
|
-
*/
|
12
|
-
const reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public';
|
13
|
-
const builtins = 'arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl';
|
14
|
-
const forbidList = new Set(`${reservedWords} ${builtins}`.split(' '));
|
15
|
-
|
16
|
-
function makeLegalIdentifier(str) {
|
17
|
-
const identifier = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(/[^$_a-zA-Z0-9]/g, '_');
|
18
|
-
|
19
|
-
if (/\d/.test(identifier[0]) || forbidList.has(identifier)) {
|
20
|
-
return `_${identifier}`;
|
21
|
-
}
|
22
|
-
|
23
|
-
return identifier || '_';
|
24
|
-
}
|
@@ -1,106 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.renderFunction = exports.index = exports.html = exports.fileSystemRoutes = void 0;
|
7
|
-
|
8
|
-
const index = ({
|
9
|
-
mountId,
|
10
|
-
imports,
|
11
|
-
renderFunction,
|
12
|
-
exportStatement
|
13
|
-
}) => `
|
14
|
-
const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
|
15
|
-
const IS_REACT18 = process.env.IS_REACT18 === 'true';
|
16
|
-
const MOUNT_ID = '${mountId}';
|
17
|
-
|
18
|
-
${imports}
|
19
|
-
|
20
|
-
let AppWrapper = null;
|
21
|
-
|
22
|
-
let root = null;
|
23
|
-
|
24
|
-
function render() {
|
25
|
-
${renderFunction}
|
26
|
-
}
|
27
|
-
|
28
|
-
AppWrapper = render();
|
29
|
-
|
30
|
-
${exportStatement};
|
31
|
-
`;
|
32
|
-
|
33
|
-
exports.index = index;
|
34
|
-
|
35
|
-
const renderFunction = ({
|
36
|
-
plugins,
|
37
|
-
customBootstrap,
|
38
|
-
fileSystemRoutes
|
39
|
-
}) => `
|
40
|
-
AppWrapper = createApp({
|
41
|
-
plugins: [
|
42
|
-
${plugins.map(({
|
43
|
-
name,
|
44
|
-
options,
|
45
|
-
args
|
46
|
-
}) => `${name}({...${options}, ...App?.config?.${args || name}}),`).join('\n')}
|
47
|
-
]
|
48
|
-
})(${fileSystemRoutes ? '' : `App`})
|
49
|
-
|
50
|
-
if (IS_BROWSER) {
|
51
|
-
${customBootstrap ? `customBootstrap(AppWrapper);` : `bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM);`}
|
52
|
-
}
|
53
|
-
|
54
|
-
return AppWrapper
|
55
|
-
`;
|
56
|
-
|
57
|
-
exports.renderFunction = renderFunction;
|
58
|
-
|
59
|
-
const html = partials => `
|
60
|
-
<!DOCTYPE html>
|
61
|
-
<html>
|
62
|
-
<head>
|
63
|
-
<%= meta %>
|
64
|
-
<title><%= title %></title>
|
65
|
-
|
66
|
-
${partials.top.join('\n')}
|
67
|
-
|
68
|
-
<script>
|
69
|
-
window.__assetPrefix__ = '<%= assetPrefix %>';
|
70
|
-
</script>
|
71
|
-
${partials.head.join('\n')}
|
72
|
-
|
73
|
-
<!--<?- chunksMap.css ?>-->
|
74
|
-
</head>
|
75
|
-
|
76
|
-
<body>
|
77
|
-
<noscript>
|
78
|
-
We're sorry but react app doesn't work properly without JavaScript enabled. Please enable it to continue.
|
79
|
-
</noscript>
|
80
|
-
<div id="<%= mountId %>"><!--<?- html ?>--></div>
|
81
|
-
${partials.body.join('\n')}
|
82
|
-
<!--<?- chunksMap.js ?>-->
|
83
|
-
<!--<?- SSRDataScript ?>-->
|
84
|
-
<!--<?- bottomTemplate ?>-->
|
85
|
-
</body>
|
86
|
-
|
87
|
-
</html>
|
88
|
-
`;
|
89
|
-
|
90
|
-
exports.html = html;
|
91
|
-
|
92
|
-
const fileSystemRoutes = ({
|
93
|
-
routes
|
94
|
-
}) => `
|
95
|
-
import loadable from '@modern-js/runtime/loadable';
|
96
|
-
|
97
|
-
${routes.map(({
|
98
|
-
component,
|
99
|
-
_component
|
100
|
-
}) => `const ${component} = loadable(() => import('${_component}'));`).join('\n\n')}
|
101
|
-
|
102
|
-
|
103
|
-
export const routes = ${JSON.stringify(routes, null, 2).replace(/"component"\s*:\s*"(\S+)"/g, '"component": $1')}
|
104
|
-
`;
|
105
|
-
|
106
|
-
exports.fileSystemRoutes = fileSystemRoutes;
|
@@ -1,113 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.walkDirectory = exports.isRouteComponentFile = exports.getDefaultImports = void 0;
|
7
|
-
|
8
|
-
var _fs = _interopRequireDefault(require("fs"));
|
9
|
-
|
10
|
-
var _path = _interopRequireDefault(require("path"));
|
11
|
-
|
12
|
-
var _utils = require("@modern-js/utils");
|
13
|
-
|
14
|
-
var _constants = require("./constants");
|
15
|
-
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
-
|
18
|
-
const walkDirectory = dir => _fs.default.readdirSync(dir).reduce((previous, filename) => {
|
19
|
-
const filePath = _path.default.join(dir, filename);
|
20
|
-
|
21
|
-
if (_fs.default.statSync(filePath).isDirectory()) {
|
22
|
-
return [...previous, ...walkDirectory(filePath)];
|
23
|
-
} else {
|
24
|
-
return [...previous, filePath];
|
25
|
-
}
|
26
|
-
}, []);
|
27
|
-
|
28
|
-
exports.walkDirectory = walkDirectory;
|
29
|
-
|
30
|
-
const getDefaultImports = ({
|
31
|
-
entrypoint,
|
32
|
-
srcDirectory,
|
33
|
-
internalSrcAlias,
|
34
|
-
internalDirAlias,
|
35
|
-
internalDirectory
|
36
|
-
}) => {
|
37
|
-
const {
|
38
|
-
entryName,
|
39
|
-
fileSystemRoutes,
|
40
|
-
customBootstrap,
|
41
|
-
entry
|
42
|
-
} = entrypoint;
|
43
|
-
const imports = [{
|
44
|
-
specifiers: [{
|
45
|
-
local: 'React'
|
46
|
-
}],
|
47
|
-
value: 'react'
|
48
|
-
}, {
|
49
|
-
specifiers: [{
|
50
|
-
local: 'ReactDOM'
|
51
|
-
}],
|
52
|
-
value: (0, _utils.isReact18)(_path.default.join(internalDirectory, '../../')) ? 'react-dom/client' : 'react-dom'
|
53
|
-
}, {
|
54
|
-
specifiers: [{
|
55
|
-
imported: 'createApp'
|
56
|
-
}, {
|
57
|
-
imported: 'bootstrap'
|
58
|
-
}],
|
59
|
-
value: '@modern-js/runtime'
|
60
|
-
}, customBootstrap && {
|
61
|
-
specifiers: [{
|
62
|
-
local: 'customBootstrap'
|
63
|
-
}],
|
64
|
-
value: (0, _utils.normalizeToPosixPath)(customBootstrap.replace(srcDirectory, internalSrcAlias))
|
65
|
-
}].filter(Boolean);
|
66
|
-
|
67
|
-
if (fileSystemRoutes) {
|
68
|
-
const route = {
|
69
|
-
specifiers: [{
|
70
|
-
imported: 'routes'
|
71
|
-
}],
|
72
|
-
value: (0, _utils.normalizeToPosixPath)(`${internalDirAlias}/${entryName}/${_constants.FILE_SYSTEM_ROUTES_FILE_NAME}`)
|
73
|
-
};
|
74
|
-
|
75
|
-
if (fileSystemRoutes.globalApp) {
|
76
|
-
imports.push({
|
77
|
-
specifiers: [{
|
78
|
-
local: 'App'
|
79
|
-
}],
|
80
|
-
value: (0, _utils.normalizeToPosixPath)(fileSystemRoutes.globalApp.replace(srcDirectory, internalSrcAlias))
|
81
|
-
});
|
82
|
-
} else {
|
83
|
-
route.initialize = 'const App = false;';
|
84
|
-
}
|
85
|
-
|
86
|
-
imports.push(route);
|
87
|
-
} else {
|
88
|
-
imports.push({
|
89
|
-
specifiers: [{
|
90
|
-
local: 'App'
|
91
|
-
}],
|
92
|
-
value: (0, _utils.normalizeToPosixPath)(entry.replace(srcDirectory, internalSrcAlias))
|
93
|
-
});
|
94
|
-
}
|
95
|
-
|
96
|
-
return imports;
|
97
|
-
};
|
98
|
-
|
99
|
-
exports.getDefaultImports = getDefaultImports;
|
100
|
-
|
101
|
-
const isRouteComponentFile = filePath => {
|
102
|
-
if (/\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/.test(filePath)) {
|
103
|
-
return false;
|
104
|
-
}
|
105
|
-
|
106
|
-
if (['.js', '.jsx', '.ts', '.tsx'].includes(_path.default.extname(filePath))) {
|
107
|
-
return true;
|
108
|
-
}
|
109
|
-
|
110
|
-
return false;
|
111
|
-
};
|
112
|
-
|
113
|
-
exports.isRouteComponentFile = isRouteComponentFile;
|
@@ -1,174 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.build = void 0;
|
7
|
-
|
8
|
-
var _webpack = require("@modern-js/webpack");
|
9
|
-
|
10
|
-
var _core = require("@modern-js/core");
|
11
|
-
|
12
|
-
var _utils = require("@modern-js/utils");
|
13
|
-
|
14
|
-
var _routes = require("../utils/routes");
|
15
|
-
|
16
|
-
var _config = require("../utils/config");
|
17
|
-
|
18
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
19
|
-
|
20
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
21
|
-
|
22
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
23
|
-
|
24
|
-
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
25
|
-
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
26
|
-
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
27
|
-
|
28
|
-
const build = async (api, options) => {
|
29
|
-
let resolvedConfig = api.useResolvedConfigContext();
|
30
|
-
const appContext = api.useAppContext();
|
31
|
-
const hookRunners = api.useHookRunners();
|
32
|
-
const {
|
33
|
-
apiOnly
|
34
|
-
} = appContext;
|
35
|
-
|
36
|
-
if (apiOnly) {
|
37
|
-
const {
|
38
|
-
appDirectory,
|
39
|
-
distDirectory,
|
40
|
-
serverConfigFile
|
41
|
-
} = appContext;
|
42
|
-
await (0, _utils.emptyDir)(distDirectory);
|
43
|
-
await hookRunners.beforeBuild({
|
44
|
-
webpackConfigs: []
|
45
|
-
});
|
46
|
-
await (0, _config.buildServerConfig)({
|
47
|
-
appDirectory,
|
48
|
-
distDirectory,
|
49
|
-
configFile: serverConfigFile
|
50
|
-
});
|
51
|
-
await (0, _routes.generateRoutes)(appContext);
|
52
|
-
await hookRunners.afterBuild();
|
53
|
-
return;
|
54
|
-
}
|
55
|
-
|
56
|
-
const webpackBuild = async (webpackConfig, type) => {
|
57
|
-
const compiler = (0, _webpack.webpack)(webpackConfig);
|
58
|
-
return new Promise((resolve, reject) => {
|
59
|
-
let label = process.env.NODE_ENV || '';
|
60
|
-
|
61
|
-
if (type && type !== 'legacy') {
|
62
|
-
label += ` ${type}`;
|
63
|
-
}
|
64
|
-
|
65
|
-
_utils.logger.info(`Creating a ${label} build...`);
|
66
|
-
|
67
|
-
compiler.run((err, stats) => {
|
68
|
-
let messages;
|
69
|
-
|
70
|
-
if (!err) {
|
71
|
-
messages = (0, _utils.formatWebpackMessages)(stats.toJson({
|
72
|
-
all: false,
|
73
|
-
warnings: true,
|
74
|
-
errors: true
|
75
|
-
}));
|
76
|
-
|
77
|
-
if (messages.errors.length === 0) {
|
78
|
-
_utils.logger.info(`File sizes after ${label} build:\n`);
|
79
|
-
|
80
|
-
(0, _utils.printFileSizesAfterBuild)(stats, previousFileSizes, distDirectory, WARN_AFTER_BUNDLE_GZIP_SIZE, WARN_AFTER_CHUNK_GZIP_SIZE);
|
81
|
-
|
82
|
-
_utils.logger.log();
|
83
|
-
}
|
84
|
-
} // When using run or watch, call close and wait for it to finish before calling run or watch again.
|
85
|
-
// Concurrent compilations will corrupt the output files.
|
86
|
-
|
87
|
-
|
88
|
-
compiler.close(closeErr => {
|
89
|
-
if (closeErr) {
|
90
|
-
_utils.logger.error(closeErr);
|
91
|
-
}
|
92
|
-
|
93
|
-
if (err) {
|
94
|
-
reject(err);
|
95
|
-
} else {
|
96
|
-
if (messages.errors.length) {
|
97
|
-
reject(new Error(messages.errors.join('\n\n')));
|
98
|
-
return;
|
99
|
-
}
|
100
|
-
|
101
|
-
resolve({
|
102
|
-
warnings: messages.warnings
|
103
|
-
});
|
104
|
-
}
|
105
|
-
});
|
106
|
-
});
|
107
|
-
});
|
108
|
-
};
|
109
|
-
|
110
|
-
resolvedConfig = _objectSpread(_objectSpread({}, resolvedConfig), {}, {
|
111
|
-
cliOptions: options
|
112
|
-
});
|
113
|
-
|
114
|
-
_core.ResolvedConfigContext.set(resolvedConfig);
|
115
|
-
|
116
|
-
const {
|
117
|
-
distDirectory,
|
118
|
-
appDirectory,
|
119
|
-
serverConfigFile
|
120
|
-
} = appContext;
|
121
|
-
const previousFileSizes = await (0, _utils.measureFileSizesBeforeBuild)(distDirectory);
|
122
|
-
await (0, _utils.emptyDir)(distDirectory);
|
123
|
-
await (0, _config.buildServerConfig)({
|
124
|
-
appDirectory,
|
125
|
-
distDirectory,
|
126
|
-
configFile: serverConfigFile
|
127
|
-
});
|
128
|
-
const buildConfigs = [];
|
129
|
-
buildConfigs.push({
|
130
|
-
type: 'legacy',
|
131
|
-
config: (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.CLIENT, appContext, resolvedConfig)
|
132
|
-
});
|
133
|
-
|
134
|
-
if (resolvedConfig.output.enableModernMode) {
|
135
|
-
buildConfigs.push({
|
136
|
-
type: 'modern',
|
137
|
-
config: (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.MODERN, appContext, resolvedConfig)
|
138
|
-
});
|
139
|
-
}
|
140
|
-
|
141
|
-
if ((0, _utils.isUseSSRBundle)(resolvedConfig)) {
|
142
|
-
buildConfigs.push({
|
143
|
-
type: 'ssr',
|
144
|
-
config: (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.NODE, appContext, resolvedConfig)
|
145
|
-
});
|
146
|
-
}
|
147
|
-
|
148
|
-
await hookRunners.beforeBuild({
|
149
|
-
webpackConfigs: buildConfigs.map(({
|
150
|
-
config
|
151
|
-
}) => config)
|
152
|
-
});
|
153
|
-
|
154
|
-
for (const buildConfig of buildConfigs) {
|
155
|
-
const {
|
156
|
-
type: buildType,
|
157
|
-
config
|
158
|
-
} = buildConfig;
|
159
|
-
|
160
|
-
try {
|
161
|
-
await webpackBuild(config, buildType);
|
162
|
-
} catch (error) {
|
163
|
-
(0, _utils.printBuildError)(error); // eslint-disable-next-line no-process-exit
|
164
|
-
|
165
|
-
process.exit(1);
|
166
|
-
}
|
167
|
-
}
|
168
|
-
|
169
|
-
await (0, _routes.generateRoutes)(appContext);
|
170
|
-
await hookRunners.afterBuild();
|
171
|
-
await (0, _config.emitResolvedConfig)(appDirectory, resolvedConfig);
|
172
|
-
};
|
173
|
-
|
174
|
-
exports.build = build;
|
@@ -1,14 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.deploy = void 0;
|
7
|
-
|
8
|
-
const deploy = async (api, options) => {
|
9
|
-
const hookRunners = api.useHookRunners();
|
10
|
-
await hookRunners.beforeDeploy(options);
|
11
|
-
await hookRunners.afterDeploy(options);
|
12
|
-
};
|
13
|
-
|
14
|
-
exports.deploy = deploy;
|