@modern-js/app-tools 0.0.0-nightly-20240228170648 → 0.0.0-nightly-20240229170649

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,7 +21,6 @@ __export(HtmlAsyncChunkPlugin_exports, {
21
21
  HtmlAsyncChunkPlugin: () => HtmlAsyncChunkPlugin
22
22
  });
23
23
  module.exports = __toCommonJS(HtmlAsyncChunkPlugin_exports);
24
- var import_define_property = require("@swc/helpers/_/_define_property");
25
24
  class HtmlAsyncChunkPlugin {
26
25
  apply(compiler) {
27
26
  compiler.hooks.compilation.tap(this.name, (compilation) => {
@@ -45,8 +44,6 @@ class HtmlAsyncChunkPlugin {
45
44
  });
46
45
  }
47
46
  constructor(htmlWebpackPlugin) {
48
- (0, import_define_property._)(this, "name", void 0);
49
- (0, import_define_property._)(this, "htmlWebpackPlugin", void 0);
50
47
  this.name = "HtmlAsyncChunkPlugin";
51
48
  this.htmlWebpackPlugin = htmlWebpackPlugin;
52
49
  }
@@ -21,7 +21,6 @@ __export(HtmlBottomTemplate_exports, {
21
21
  BottomTemplatePlugin: () => BottomTemplatePlugin
22
22
  });
23
23
  module.exports = __toCommonJS(HtmlBottomTemplate_exports);
24
- var import_define_property = require("@swc/helpers/_/_define_property");
25
24
  class BottomTemplatePlugin {
26
25
  apply(compiler) {
27
26
  compiler.hooks.compilation.tap(this.name, (compilation) => {
@@ -44,10 +43,8 @@ ${match}`);
44
43
  });
45
44
  }
46
45
  constructor(htmlWebpackPlugin) {
47
- (0, import_define_property._)(this, "htmlWebpackPlugin", void 0);
48
- (0, import_define_property._)(this, "bottomTemplateReg", /<!--<\?-\s*bottomTemplate\s*\?>-->/);
49
- (0, import_define_property._)(this, "bodyRegExp", /(<\/\s*body\s*>)/i);
50
- (0, import_define_property._)(this, "name", void 0);
46
+ this.bottomTemplateReg = /<!--<\?-\s*bottomTemplate\s*\?>-->/;
47
+ this.bodyRegExp = /(<\/\s*body\s*>)/i;
51
48
  this.htmlWebpackPlugin = htmlWebpackPlugin;
52
49
  this.name = "bottom-template";
53
50
  }
@@ -21,7 +21,6 @@ __export(RouterPlugin_exports, {
21
21
  RouterPlugin: () => RouterPlugin
22
22
  });
23
23
  module.exports = __toCommonJS(RouterPlugin_exports);
24
- var import_define_property = require("@swc/helpers/_/_define_property");
25
24
  var import_crypto = require("crypto");
26
25
  var import_lodash = require("@modern-js/utils/lodash");
27
26
  var import_utils = require("@modern-js/utils");
@@ -229,13 +228,7 @@ class RouterPlugin {
229
228
  });
230
229
  }
231
230
  constructor({ staticJsDir = "static/js", HtmlBundlerPlugin, enableInlineRouteManifests, disableFilenameHash = false, scriptLoading = "defer", nonce }) {
232
- (0, import_define_property._)(this, "name", "RouterPlugin");
233
- (0, import_define_property._)(this, "HtmlBundlerPlugin", void 0);
234
- (0, import_define_property._)(this, "enableInlineRouteManifests", void 0);
235
- (0, import_define_property._)(this, "staticJsDir", void 0);
236
- (0, import_define_property._)(this, "disableFilenameHash", void 0);
237
- (0, import_define_property._)(this, "scriptLoading", void 0);
238
- (0, import_define_property._)(this, "nonce", void 0);
231
+ this.name = "RouterPlugin";
239
232
  this.HtmlBundlerPlugin = HtmlBundlerPlugin;
240
233
  this.enableInlineRouteManifests = enableInlineRouteManifests;
241
234
  this.staticJsDir = staticJsDir;
@@ -1,57 +1,49 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
2
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
5
3
  var HtmlAsyncChunkPlugin = /* @__PURE__ */ function() {
6
4
  "use strict";
7
5
  function HtmlAsyncChunkPlugin2(htmlWebpackPlugin) {
8
6
  _class_call_check(this, HtmlAsyncChunkPlugin2);
9
- _define_property(this, "name", void 0);
10
- _define_property(this, "htmlWebpackPlugin", void 0);
11
7
  this.name = "HtmlAsyncChunkPlugin";
12
8
  this.htmlWebpackPlugin = htmlWebpackPlugin;
13
9
  }
14
- _create_class(HtmlAsyncChunkPlugin2, [
15
- {
16
- key: "apply",
17
- value: function apply(compiler) {
18
- var _this = this;
19
- compiler.hooks.compilation.tap(this.name, function(compilation) {
20
- var hooks = _this.htmlWebpackPlugin.getHooks(compilation);
21
- hooks.alterAssetTagGroups.tap(_this.name, function(assets) {
22
- var tags = _to_consumable_array(assets.headTags).concat(_to_consumable_array(assets.bodyTags));
23
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
24
- try {
25
- for (var _iterator = tags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
26
- var tag = _step.value;
27
- if (tag.tagName === "script") {
28
- var attributes = tag.attributes;
29
- if (attributes && attributes.defer === true) {
30
- attributes.async = true;
31
- delete attributes.defer;
32
- }
33
- }
34
- }
35
- } catch (err) {
36
- _didIteratorError = true;
37
- _iteratorError = err;
38
- } finally {
39
- try {
40
- if (!_iteratorNormalCompletion && _iterator.return != null) {
41
- _iterator.return();
42
- }
43
- } finally {
44
- if (_didIteratorError) {
45
- throw _iteratorError;
46
- }
10
+ var _proto = HtmlAsyncChunkPlugin2.prototype;
11
+ _proto.apply = function apply(compiler) {
12
+ var _this = this;
13
+ compiler.hooks.compilation.tap(this.name, function(compilation) {
14
+ var hooks = _this.htmlWebpackPlugin.getHooks(compilation);
15
+ hooks.alterAssetTagGroups.tap(_this.name, function(assets) {
16
+ var tags = _to_consumable_array(assets.headTags).concat(_to_consumable_array(assets.bodyTags));
17
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
18
+ try {
19
+ for (var _iterator = tags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
20
+ var tag = _step.value;
21
+ if (tag.tagName === "script") {
22
+ var attributes = tag.attributes;
23
+ if (attributes && attributes.defer === true) {
24
+ attributes.async = true;
25
+ delete attributes.defer;
47
26
  }
48
27
  }
49
- return assets;
50
- });
51
- });
52
- }
53
- }
54
- ]);
28
+ }
29
+ } catch (err) {
30
+ _didIteratorError = true;
31
+ _iteratorError = err;
32
+ } finally {
33
+ try {
34
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
35
+ _iterator.return();
36
+ }
37
+ } finally {
38
+ if (_didIteratorError) {
39
+ throw _iteratorError;
40
+ }
41
+ }
42
+ }
43
+ return assets;
44
+ });
45
+ });
46
+ };
55
47
  return HtmlAsyncChunkPlugin2;
56
48
  }();
57
49
  export {
@@ -1,43 +1,35 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
2
  var BottomTemplatePlugin = /* @__PURE__ */ function() {
5
3
  "use strict";
6
4
  function BottomTemplatePlugin2(htmlWebpackPlugin) {
7
5
  _class_call_check(this, BottomTemplatePlugin2);
8
- _define_property(this, "htmlWebpackPlugin", void 0);
9
- _define_property(this, "bottomTemplateReg", /<!--<\?-\s*bottomTemplate\s*\?>-->/);
10
- _define_property(this, "bodyRegExp", /(<\/\s*body\s*>)/i);
11
- _define_property(this, "name", void 0);
6
+ this.bottomTemplateReg = /<!--<\?-\s*bottomTemplate\s*\?>-->/;
7
+ this.bodyRegExp = /(<\/\s*body\s*>)/i;
12
8
  this.htmlWebpackPlugin = htmlWebpackPlugin;
13
9
  this.name = "bottom-template";
14
10
  }
15
- _create_class(BottomTemplatePlugin2, [
16
- {
17
- key: "apply",
18
- value: function apply(compiler) {
19
- var _this = this;
20
- compiler.hooks.compilation.tap(this.name, function(compilation) {
21
- _this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(_this.name, function(data) {
22
- var _data_plugin_options;
23
- if (!((_data_plugin_options = data.plugin.options) === null || _data_plugin_options === void 0 ? void 0 : _data_plugin_options.__internal__)) {
24
- return data;
25
- }
26
- if (_this.bottomTemplateReg.test(data.html)) {
27
- data.html = data.html.replace(_this.bottomTemplateReg, "");
28
- var bottomTemplate = data.plugin.options.bottomTemplate;
29
- if (bottomTemplate) {
30
- data.html = data.html.replace(_this.bodyRegExp, function(match) {
31
- return "\n".concat(bottomTemplate, "\n").concat(match);
32
- });
33
- }
34
- }
35
- return data;
36
- });
37
- });
38
- }
39
- }
40
- ]);
11
+ var _proto = BottomTemplatePlugin2.prototype;
12
+ _proto.apply = function apply(compiler) {
13
+ var _this = this;
14
+ compiler.hooks.compilation.tap(this.name, function(compilation) {
15
+ _this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(_this.name, function(data) {
16
+ var _data_plugin_options;
17
+ if (!((_data_plugin_options = data.plugin.options) === null || _data_plugin_options === void 0 ? void 0 : _data_plugin_options.__internal__)) {
18
+ return data;
19
+ }
20
+ if (_this.bottomTemplateReg.test(data.html)) {
21
+ data.html = data.html.replace(_this.bottomTemplateReg, "");
22
+ var bottomTemplate = data.plugin.options.bottomTemplate;
23
+ if (bottomTemplate) {
24
+ data.html = data.html.replace(_this.bodyRegExp, function(match) {
25
+ return "\n".concat(bottomTemplate, "\n").concat(match);
26
+ });
27
+ }
28
+ }
29
+ return data;
30
+ });
31
+ });
32
+ };
41
33
  return BottomTemplatePlugin2;
42
34
  }();
43
35
  export {
@@ -1,7 +1,5 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
3
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
4
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
5
3
  import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
6
4
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
7
5
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
@@ -18,13 +16,7 @@ var RouterPlugin = /* @__PURE__ */ function() {
18
16
  function RouterPlugin2(param) {
19
17
  var _param_staticJsDir = param.staticJsDir, staticJsDir = _param_staticJsDir === void 0 ? "static/js" : _param_staticJsDir, HtmlBundlerPlugin = param.HtmlBundlerPlugin, enableInlineRouteManifests = param.enableInlineRouteManifests, _param_disableFilenameHash = param.disableFilenameHash, disableFilenameHash = _param_disableFilenameHash === void 0 ? false : _param_disableFilenameHash, _param_scriptLoading = param.scriptLoading, scriptLoading = _param_scriptLoading === void 0 ? "defer" : _param_scriptLoading, nonce = param.nonce;
20
18
  _class_call_check(this, RouterPlugin2);
21
- _define_property(this, "name", "RouterPlugin");
22
- _define_property(this, "HtmlBundlerPlugin", void 0);
23
- _define_property(this, "enableInlineRouteManifests", void 0);
24
- _define_property(this, "staticJsDir", void 0);
25
- _define_property(this, "disableFilenameHash", void 0);
26
- _define_property(this, "scriptLoading", void 0);
27
- _define_property(this, "nonce", void 0);
19
+ this.name = "RouterPlugin";
28
20
  this.HtmlBundlerPlugin = HtmlBundlerPlugin;
29
21
  this.enableInlineRouteManifests = enableInlineRouteManifests;
30
22
  this.staticJsDir = staticJsDir;
@@ -32,276 +24,263 @@ var RouterPlugin = /* @__PURE__ */ function() {
32
24
  this.scriptLoading = scriptLoading;
33
25
  this.nonce = nonce;
34
26
  }
35
- _create_class(RouterPlugin2, [
36
- {
37
- key: "isTargetNodeOrWebWorker",
38
- value: function isTargetNodeOrWebWorker(target) {
39
- if (target === "node" || Array.isArray(target) && target.includes("node")) {
40
- return true;
41
- }
42
- if (target === "webworker" || Array.isArray(target) && target.includes("webworker")) {
43
- return true;
44
- }
45
- return false;
46
- }
47
- },
48
- {
49
- key: "getEntryChunks",
50
- value: function getEntryChunks(compilation, chunks) {
51
- var entrypointsArray = Array.from(compilation.entrypoints.entries());
52
- var entryChunkIds = entrypointsArray.map(function(entrypoint) {
53
- return entrypoint[0];
54
- });
55
- var entryChunks = _to_consumable_array(chunks).filter(function(chunk) {
56
- var _chunk_names;
57
- return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some(function(name) {
58
- return entryChunkIds.includes(name);
59
- });
60
- });
61
- return entryChunks;
62
- }
63
- },
64
- {
65
- key: "getEntryChunkFiles",
66
- value: function getEntryChunkFiles(entryChunks) {
67
- return entryChunks.map(function(chunk) {
68
- return _to_consumable_array(chunk.files || []).find(function(fname) {
69
- return fname.includes(".js");
70
- });
71
- });
27
+ var _proto = RouterPlugin2.prototype;
28
+ _proto.isTargetNodeOrWebWorker = function isTargetNodeOrWebWorker(target) {
29
+ if (target === "node" || Array.isArray(target) && target.includes("node")) {
30
+ return true;
31
+ }
32
+ if (target === "webworker" || Array.isArray(target) && target.includes("webworker")) {
33
+ return true;
34
+ }
35
+ return false;
36
+ };
37
+ _proto.getEntryChunks = function getEntryChunks(compilation, chunks) {
38
+ var entrypointsArray = Array.from(compilation.entrypoints.entries());
39
+ var entryChunkIds = entrypointsArray.map(function(entrypoint) {
40
+ return entrypoint[0];
41
+ });
42
+ var entryChunks = _to_consumable_array(chunks).filter(function(chunk) {
43
+ var _chunk_names;
44
+ return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some(function(name) {
45
+ return entryChunkIds.includes(name);
46
+ });
47
+ });
48
+ return entryChunks;
49
+ };
50
+ _proto.getEntryChunkFiles = function getEntryChunkFiles(entryChunks) {
51
+ return entryChunks.map(function(chunk) {
52
+ return _to_consumable_array(chunk.files || []).find(function(fname) {
53
+ return fname.includes(".js");
54
+ });
55
+ });
56
+ };
57
+ _proto.apply = function apply(compiler) {
58
+ var _this = this;
59
+ var target = compiler.options.target;
60
+ if (this.isTargetNodeOrWebWorker(target)) {
61
+ return;
62
+ }
63
+ var webpack = compiler.webpack;
64
+ var isRspack = "rspackVersion" in webpack;
65
+ var Compilation = webpack.Compilation, sources = webpack.sources;
66
+ var RawSource = sources.RawSource;
67
+ var normalizePath = function(path) {
68
+ if (!path.endsWith("/")) {
69
+ return "".concat(path, "/");
72
70
  }
73
- },
74
- {
75
- key: "apply",
76
- value: function apply(compiler) {
77
- var _this = this;
78
- var target = compiler.options.target;
79
- if (this.isTargetNodeOrWebWorker(target)) {
80
- return;
81
- }
82
- var webpack = compiler.webpack;
83
- var isRspack = "rspackVersion" in webpack;
84
- var Compilation = webpack.Compilation, sources = webpack.sources;
85
- var RawSource = sources.RawSource;
86
- var normalizePath = function(path) {
87
- if (!path.endsWith("/")) {
88
- return "".concat(path, "/");
89
- }
90
- return path;
91
- };
92
- var chunksToHtmlName = /* @__PURE__ */ new Map();
93
- var ROUTE_MANIFEST_HOLDER = "route-manifest";
94
- var placeholder = "<!--<?- ".concat(ROUTE_MANIFEST_HOLDER, " ?>-->");
95
- compiler.hooks.thisCompilation.tap(PLUGIN_NAME, function(compilation) {
96
- _this.HtmlBundlerPlugin.getHooks(compilation).beforeEmit.tapAsync("RouterManifestPlugin", function(data, callback) {
97
- var outputName = data.outputName;
98
- var chunks = data.plugin.options.chunks;
99
- chunksToHtmlName.set(chunks, outputName);
100
- data.html = data.html.replace("</script>", "</script>".concat(placeholder));
101
- callback(null, data);
102
- });
103
- var _this1 = _this;
104
- compilation.hooks.processAssets.tapPromise({
105
- name: PLUGIN_NAME,
106
- stage: Compilation.PROCESS_ASSETS_STAGE_REPORT
107
- }, /* @__PURE__ */ _async_to_generator(function() {
108
- var _loop, stats, publicPath, _stats_chunks, chunks, namedChunkGroups, routeAssets, prevManifestAsset, prevManifestStr, prevManifest, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, name, chunkGroup, assets, referenceCssAssets, manifest, entryNames, entryChunks, orignalEntryIds, entryChunkFiles, entryChunkFileIds, i;
109
- return _ts_generator(this, function(_state) {
110
- _loop = function(i2) {
111
- var entryName = entryNames[i2];
112
- var file = entryChunkFiles[i2];
113
- var chunkNames = entryChunks[i2].names;
114
- var chunkId = entryChunkFileIds[i2];
115
- var asset = compilation.assets[file];
116
- if (!asset || !chunkId) {
117
- return "continue";
118
- }
119
- var relatedAssets = {};
120
- if (entryChunkFiles.length > 1) {
121
- Object.keys(routeAssets).forEach(function(routeId) {
122
- var segments = routeId.split("_");
123
- var chunkName = segments[0];
124
- if (chunkNames === null || chunkNames === void 0 ? void 0 : chunkNames.includes(chunkName)) {
125
- relatedAssets[routeId] = routeAssets[routeId];
126
- }
127
- });
128
- } else {
129
- relatedAssets = routeAssets;
130
- }
131
- var manifest2 = {
132
- routeAssets: relatedAssets
133
- };
134
- var injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest2, function(k, v) {
135
- if ((k === "assets" || k === "referenceCssAssets") && Array.isArray(v)) {
136
- return v.map(function(item) {
137
- return item.replace(publicPath, "");
138
- });
139
- }
140
- return v;
141
- }), ";\n })();\n ");
142
- var htmlName = void 0;
143
- var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
144
- try {
145
- var _loop2 = function() {
146
- var _step_value2 = _sliced_to_array(_step2.value, 2), chunks2 = _step_value2[0], name2 = _step_value2[1];
147
- if (Array.isArray(chunkNames) && Array.isArray(chunks2) && chunkNames.every(function(value, index) {
148
- return value === chunks2[index];
149
- })) {
150
- htmlName = name2;
151
- return "break";
152
- }
153
- };
154
- for (var _iterator2 = chunksToHtmlName.entries()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
155
- var _ret = _loop2();
156
- if (_ret === "break")
157
- break;
158
- }
159
- } catch (err) {
160
- _didIteratorError2 = true;
161
- _iteratorError2 = err;
162
- } finally {
163
- try {
164
- if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
165
- _iterator2.return();
166
- }
167
- } finally {
168
- if (_didIteratorError2) {
169
- throw _iteratorError2;
170
- }
171
- }
71
+ return path;
72
+ };
73
+ var chunksToHtmlName = /* @__PURE__ */ new Map();
74
+ var ROUTE_MANIFEST_HOLDER = "route-manifest";
75
+ var placeholder = "<!--<?- ".concat(ROUTE_MANIFEST_HOLDER, " ?>-->");
76
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, function(compilation) {
77
+ _this.HtmlBundlerPlugin.getHooks(compilation).beforeEmit.tapAsync("RouterManifestPlugin", function(data, callback) {
78
+ var outputName = data.outputName;
79
+ var chunks = data.plugin.options.chunks;
80
+ chunksToHtmlName.set(chunks, outputName);
81
+ data.html = data.html.replace("</script>", "</script>".concat(placeholder));
82
+ callback(null, data);
83
+ });
84
+ var _this1 = _this;
85
+ compilation.hooks.processAssets.tapPromise({
86
+ name: PLUGIN_NAME,
87
+ stage: Compilation.PROCESS_ASSETS_STAGE_REPORT
88
+ }, /* @__PURE__ */ _async_to_generator(function() {
89
+ var _loop, stats, publicPath, _stats_chunks, chunks, namedChunkGroups, routeAssets, prevManifestAsset, prevManifestStr, prevManifest, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, name, chunkGroup, assets, referenceCssAssets, manifest, entryNames, entryChunks, orignalEntryIds, entryChunkFiles, entryChunkFileIds, i;
90
+ return _ts_generator(this, function(_state) {
91
+ _loop = function(i2) {
92
+ var entryName = entryNames[i2];
93
+ var file = entryChunkFiles[i2];
94
+ var chunkNames = entryChunks[i2].names;
95
+ var chunkId = entryChunkFileIds[i2];
96
+ var asset = compilation.assets[file];
97
+ if (!asset || !chunkId) {
98
+ return "continue";
99
+ }
100
+ var relatedAssets = {};
101
+ if (entryChunkFiles.length > 1) {
102
+ Object.keys(routeAssets).forEach(function(routeId) {
103
+ var segments = routeId.split("_");
104
+ var chunkName = segments[0];
105
+ if (chunkNames === null || chunkNames === void 0 ? void 0 : chunkNames.includes(chunkName)) {
106
+ relatedAssets[routeId] = routeAssets[routeId];
172
107
  }
173
- var oldHtml = compilation.assets[htmlName];
174
- var enableInlineRouteManifests = _this1.enableInlineRouteManifests, disableFilenameHash = _this1.disableFilenameHash, staticJsDir = _this1.staticJsDir, scriptLoading = _this1.scriptLoading, nonce = _this1.nonce;
175
- var nonceAttr = nonce ? 'nonce="'.concat(nonce, '"') : "";
176
- if (oldHtml) {
177
- if (enableInlineRouteManifests) {
178
- compilation.updateAsset(
179
- htmlName,
180
- new RawSource(oldHtml.source().toString().replace(placeholder, "<script ".concat(nonceAttr, ">").concat(injectedContent, "</script>"))),
181
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
182
- void 0
183
- );
184
- } else {
185
- var scriptPath = "".concat(staticJsDir, "/").concat(ROUTE_MANIFEST_HOLDER, "-").concat(entryName).concat(disableFilenameHash ? ".js" : ".".concat(generateContentHash(injectedContent), ".js"));
186
- var scriptUrl = "".concat(publicPath).concat(scriptPath);
187
- var scriptLoadingAttr = (
188
- // eslint-disable-next-line no-nested-ternary
189
- scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? 'type="module"' : ""
190
- );
191
- var script = "<script ".concat(scriptLoadingAttr, " ").concat(nonceAttr, ' src="').concat(scriptUrl, '"></script>');
192
- compilation.updateAsset(
193
- htmlName,
194
- new RawSource(oldHtml.source().toString().replace(placeholder, script)),
195
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
196
- void 0
197
- );
198
- compilation.emitAsset(scriptPath, new RawSource(injectedContent));
199
- }
108
+ });
109
+ } else {
110
+ relatedAssets = routeAssets;
111
+ }
112
+ var manifest2 = {
113
+ routeAssets: relatedAssets
114
+ };
115
+ var injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest2, function(k, v) {
116
+ if ((k === "assets" || k === "referenceCssAssets") && Array.isArray(v)) {
117
+ return v.map(function(item) {
118
+ return item.replace(publicPath, "");
119
+ });
120
+ }
121
+ return v;
122
+ }), ";\n })();\n ");
123
+ var htmlName = void 0;
124
+ var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
125
+ try {
126
+ var _loop2 = function() {
127
+ var _step_value2 = _sliced_to_array(_step2.value, 2), chunks2 = _step_value2[0], name2 = _step_value2[1];
128
+ if (Array.isArray(chunkNames) && Array.isArray(chunks2) && chunkNames.every(function(value, index) {
129
+ return value === chunks2[index];
130
+ })) {
131
+ htmlName = name2;
132
+ return "break";
200
133
  }
201
134
  };
202
- stats = compilation.getStats().toJson({
203
- all: false,
204
- publicPath: true,
205
- assets: true,
206
- chunkGroups: true,
207
- chunks: true,
208
- ids: true
209
- });
210
- publicPath = stats.publicPath, _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks, namedChunkGroups = stats.namedChunkGroups;
211
- routeAssets = {};
212
- if (!namedChunkGroups) {
213
- return [
214
- 2
215
- ];
135
+ for (var _iterator2 = chunksToHtmlName.entries()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
136
+ var _ret = _loop2();
137
+ if (_ret === "break")
138
+ break;
216
139
  }
217
- prevManifestAsset = compilation.getAsset(ROUTE_MANIFEST_FILE);
218
- prevManifestStr = prevManifestAsset ? prevManifestAsset.source.source().toString() : JSON.stringify({
219
- routeAssets: {}
220
- });
221
- prevManifest = JSON.parse(prevManifestStr);
222
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
140
+ } catch (err) {
141
+ _didIteratorError2 = true;
142
+ _iteratorError2 = err;
143
+ } finally {
223
144
  try {
224
- for (_iterator = Object.entries(namedChunkGroups)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
225
- _step_value = _sliced_to_array(_step.value, 2), name = _step_value[0], chunkGroup = _step_value[1];
226
- assets = chunkGroup.assets.map(function(asset) {
227
- var filename = asset.name;
228
- return publicPath ? normalizePath(publicPath) + filename : filename;
229
- });
230
- referenceCssAssets = assets.filter(function(asset) {
231
- return /\.css$/.test(asset);
232
- });
233
- routeAssets[name] = {
234
- chunkIds: chunkGroup.chunks,
235
- assets,
236
- referenceCssAssets
237
- };
238
- if (prevManifest.routeAssets[name]) {
239
- mergeWith(routeAssets[name], prevManifest.routeAssets[name], function(obj, source) {
240
- if (Array.isArray(obj)) {
241
- return obj.concat(source);
242
- }
243
- return Object.assign(source, obj);
244
- });
245
- }
145
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
146
+ _iterator2.return();
246
147
  }
247
- } catch (err) {
248
- _didIteratorError = true;
249
- _iteratorError = err;
250
148
  } finally {
251
- try {
252
- if (!_iteratorNormalCompletion && _iterator.return != null) {
253
- _iterator.return();
254
- }
255
- } finally {
256
- if (_didIteratorError) {
257
- throw _iteratorError;
258
- }
149
+ if (_didIteratorError2) {
150
+ throw _iteratorError2;
259
151
  }
260
152
  }
261
- manifest = {
262
- routeAssets
263
- };
264
- entryNames = Array.from(compilation.entrypoints.keys());
265
- entryChunks = [];
266
- if (isRspack) {
267
- entryChunks = _this1.getEntryChunks(compilation, chunks);
268
- } else {
269
- orignalEntryIds = Object.keys(compilation.options.entry).map(function(entryName) {
270
- var chunk = compilation.namedChunks.get(entryName);
271
- if (chunk) {
272
- return chunk.id;
273
- }
274
- return entryName;
275
- });
276
- entryChunks = _this1.getEntryChunks(compilation, chunks).filter(function(chunk) {
277
- return orignalEntryIds.includes(chunk.id);
278
- });
279
- }
280
- entryChunkFiles = _this1.getEntryChunkFiles(entryChunks);
281
- entryChunkFileIds = entryChunks.map(function(chunk) {
282
- return chunk.id;
283
- });
284
- for (i = 0; i < entryChunkFiles.length; i++)
285
- _loop(i);
286
- if (prevManifestAsset) {
153
+ }
154
+ var oldHtml = compilation.assets[htmlName];
155
+ var enableInlineRouteManifests = _this1.enableInlineRouteManifests, disableFilenameHash = _this1.disableFilenameHash, staticJsDir = _this1.staticJsDir, scriptLoading = _this1.scriptLoading, nonce = _this1.nonce;
156
+ var nonceAttr = nonce ? 'nonce="'.concat(nonce, '"') : "";
157
+ if (oldHtml) {
158
+ if (enableInlineRouteManifests) {
287
159
  compilation.updateAsset(
288
- ROUTE_MANIFEST_FILE,
289
- new RawSource(JSON.stringify(manifest, null, 2)),
160
+ htmlName,
161
+ new RawSource(oldHtml.source().toString().replace(placeholder, "<script ".concat(nonceAttr, ">").concat(injectedContent, "</script>"))),
290
162
  // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
291
163
  void 0
292
164
  );
293
165
  } else {
294
- compilation.emitAsset(ROUTE_MANIFEST_FILE, new RawSource(JSON.stringify(manifest, null, 2)));
166
+ var scriptPath = "".concat(staticJsDir, "/").concat(ROUTE_MANIFEST_HOLDER, "-").concat(entryName).concat(disableFilenameHash ? ".js" : ".".concat(generateContentHash(injectedContent), ".js"));
167
+ var scriptUrl = "".concat(publicPath).concat(scriptPath);
168
+ var scriptLoadingAttr = (
169
+ // eslint-disable-next-line no-nested-ternary
170
+ scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? 'type="module"' : ""
171
+ );
172
+ var script = "<script ".concat(scriptLoadingAttr, " ").concat(nonceAttr, ' src="').concat(scriptUrl, '"></script>');
173
+ compilation.updateAsset(
174
+ htmlName,
175
+ new RawSource(oldHtml.source().toString().replace(placeholder, script)),
176
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
177
+ void 0
178
+ );
179
+ compilation.emitAsset(scriptPath, new RawSource(injectedContent));
295
180
  }
296
- return [
297
- 2
298
- ];
181
+ }
182
+ };
183
+ stats = compilation.getStats().toJson({
184
+ all: false,
185
+ publicPath: true,
186
+ assets: true,
187
+ chunkGroups: true,
188
+ chunks: true,
189
+ ids: true
190
+ });
191
+ publicPath = stats.publicPath, _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks, namedChunkGroups = stats.namedChunkGroups;
192
+ routeAssets = {};
193
+ if (!namedChunkGroups) {
194
+ return [
195
+ 2
196
+ ];
197
+ }
198
+ prevManifestAsset = compilation.getAsset(ROUTE_MANIFEST_FILE);
199
+ prevManifestStr = prevManifestAsset ? prevManifestAsset.source.source().toString() : JSON.stringify({
200
+ routeAssets: {}
201
+ });
202
+ prevManifest = JSON.parse(prevManifestStr);
203
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
204
+ try {
205
+ for (_iterator = Object.entries(namedChunkGroups)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
206
+ _step_value = _sliced_to_array(_step.value, 2), name = _step_value[0], chunkGroup = _step_value[1];
207
+ assets = chunkGroup.assets.map(function(asset) {
208
+ var filename = asset.name;
209
+ return publicPath ? normalizePath(publicPath) + filename : filename;
210
+ });
211
+ referenceCssAssets = assets.filter(function(asset) {
212
+ return /\.css$/.test(asset);
213
+ });
214
+ routeAssets[name] = {
215
+ chunkIds: chunkGroup.chunks,
216
+ assets,
217
+ referenceCssAssets
218
+ };
219
+ if (prevManifest.routeAssets[name]) {
220
+ mergeWith(routeAssets[name], prevManifest.routeAssets[name], function(obj, source) {
221
+ if (Array.isArray(obj)) {
222
+ return obj.concat(source);
223
+ }
224
+ return Object.assign(source, obj);
225
+ });
226
+ }
227
+ }
228
+ } catch (err) {
229
+ _didIteratorError = true;
230
+ _iteratorError = err;
231
+ } finally {
232
+ try {
233
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
234
+ _iterator.return();
235
+ }
236
+ } finally {
237
+ if (_didIteratorError) {
238
+ throw _iteratorError;
239
+ }
240
+ }
241
+ }
242
+ manifest = {
243
+ routeAssets
244
+ };
245
+ entryNames = Array.from(compilation.entrypoints.keys());
246
+ entryChunks = [];
247
+ if (isRspack) {
248
+ entryChunks = _this1.getEntryChunks(compilation, chunks);
249
+ } else {
250
+ orignalEntryIds = Object.keys(compilation.options.entry).map(function(entryName) {
251
+ var chunk = compilation.namedChunks.get(entryName);
252
+ if (chunk) {
253
+ return chunk.id;
254
+ }
255
+ return entryName;
256
+ });
257
+ entryChunks = _this1.getEntryChunks(compilation, chunks).filter(function(chunk) {
258
+ return orignalEntryIds.includes(chunk.id);
299
259
  });
300
- }));
260
+ }
261
+ entryChunkFiles = _this1.getEntryChunkFiles(entryChunks);
262
+ entryChunkFileIds = entryChunks.map(function(chunk) {
263
+ return chunk.id;
264
+ });
265
+ for (i = 0; i < entryChunkFiles.length; i++)
266
+ _loop(i);
267
+ if (prevManifestAsset) {
268
+ compilation.updateAsset(
269
+ ROUTE_MANIFEST_FILE,
270
+ new RawSource(JSON.stringify(manifest, null, 2)),
271
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
272
+ void 0
273
+ );
274
+ } else {
275
+ compilation.emitAsset(ROUTE_MANIFEST_FILE, new RawSource(JSON.stringify(manifest, null, 2)));
276
+ }
277
+ return [
278
+ 2
279
+ ];
301
280
  });
302
- }
303
- }
304
- ]);
281
+ }));
282
+ });
283
+ };
305
284
  return RouterPlugin2;
306
285
  }();
307
286
  export {
@@ -1,4 +1,3 @@
1
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
1
  class HtmlAsyncChunkPlugin {
3
2
  apply(compiler) {
4
3
  compiler.hooks.compilation.tap(this.name, (compilation) => {
@@ -22,8 +21,6 @@ class HtmlAsyncChunkPlugin {
22
21
  });
23
22
  }
24
23
  constructor(htmlWebpackPlugin) {
25
- _define_property(this, "name", void 0);
26
- _define_property(this, "htmlWebpackPlugin", void 0);
27
24
  this.name = "HtmlAsyncChunkPlugin";
28
25
  this.htmlWebpackPlugin = htmlWebpackPlugin;
29
26
  }
@@ -1,4 +1,3 @@
1
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
1
  class BottomTemplatePlugin {
3
2
  apply(compiler) {
4
3
  compiler.hooks.compilation.tap(this.name, (compilation) => {
@@ -21,10 +20,8 @@ ${match}`);
21
20
  });
22
21
  }
23
22
  constructor(htmlWebpackPlugin) {
24
- _define_property(this, "htmlWebpackPlugin", void 0);
25
- _define_property(this, "bottomTemplateReg", /<!--<\?-\s*bottomTemplate\s*\?>-->/);
26
- _define_property(this, "bodyRegExp", /(<\/\s*body\s*>)/i);
27
- _define_property(this, "name", void 0);
23
+ this.bottomTemplateReg = /<!--<\?-\s*bottomTemplate\s*\?>-->/;
24
+ this.bodyRegExp = /(<\/\s*body\s*>)/i;
28
25
  this.htmlWebpackPlugin = htmlWebpackPlugin;
29
26
  this.name = "bottom-template";
30
27
  }
@@ -1,4 +1,3 @@
1
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
1
  import { createHash } from "crypto";
3
2
  import { mergeWith } from "@modern-js/utils/lodash";
4
3
  import { ROUTE_MANIFEST_FILE } from "@modern-js/utils";
@@ -206,13 +205,7 @@ class RouterPlugin {
206
205
  });
207
206
  }
208
207
  constructor({ staticJsDir = "static/js", HtmlBundlerPlugin, enableInlineRouteManifests, disableFilenameHash = false, scriptLoading = "defer", nonce }) {
209
- _define_property(this, "name", "RouterPlugin");
210
- _define_property(this, "HtmlBundlerPlugin", void 0);
211
- _define_property(this, "enableInlineRouteManifests", void 0);
212
- _define_property(this, "staticJsDir", void 0);
213
- _define_property(this, "disableFilenameHash", void 0);
214
- _define_property(this, "scriptLoading", void 0);
215
- _define_property(this, "nonce", void 0);
208
+ this.name = "RouterPlugin";
216
209
  this.HtmlBundlerPlugin = HtmlBundlerPlugin;
217
210
  this.enableInlineRouteManifests = enableInlineRouteManifests;
218
211
  this.staticJsDir = staticJsDir;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "0.0.0-nightly-20240228170648",
18
+ "version": "0.0.0-nightly-20240229170649",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -76,19 +76,19 @@
76
76
  "es-module-lexer": "^1.1.0",
77
77
  "esbuild": "0.17.19",
78
78
  "@swc/helpers": "0.5.3",
79
- "@modern-js/uni-builder": "0.0.0-nightly-20240228170648",
80
- "@modern-js/core": "0.0.0-nightly-20240228170648",
81
- "@modern-js/node-bundle-require": "0.0.0-nightly-20240228170648",
82
- "@modern-js/plugin": "0.0.0-nightly-20240228170648",
83
- "@modern-js/plugin-data-loader": "0.0.0-nightly-20240228170648",
84
- "@modern-js/plugin-i18n": "0.0.0-nightly-20240228170648",
85
- "@modern-js/plugin-lint": "0.0.0-nightly-20240228170648",
86
- "@modern-js/server": "0.0.0-nightly-20240228170648",
87
- "@modern-js/prod-server": "0.0.0-nightly-20240228170648",
88
- "@modern-js/types": "0.0.0-nightly-20240228170648",
89
- "@modern-js/server-utils": "0.0.0-nightly-20240228170648",
90
- "@modern-js/utils": "0.0.0-nightly-20240228170648",
91
- "@modern-js/server-core": "0.0.0-nightly-20240228170648"
79
+ "@modern-js/uni-builder": "0.0.0-nightly-20240229170649",
80
+ "@modern-js/core": "0.0.0-nightly-20240229170649",
81
+ "@modern-js/plugin-data-loader": "0.0.0-nightly-20240229170649",
82
+ "@modern-js/node-bundle-require": "0.0.0-nightly-20240229170649",
83
+ "@modern-js/plugin": "0.0.0-nightly-20240229170649",
84
+ "@modern-js/plugin-i18n": "0.0.0-nightly-20240229170649",
85
+ "@modern-js/prod-server": "0.0.0-nightly-20240229170649",
86
+ "@modern-js/types": "0.0.0-nightly-20240229170649",
87
+ "@modern-js/plugin-lint": "0.0.0-nightly-20240229170649",
88
+ "@modern-js/server-utils": "0.0.0-nightly-20240229170649",
89
+ "@modern-js/server": "0.0.0-nightly-20240229170649",
90
+ "@modern-js/utils": "0.0.0-nightly-20240229170649",
91
+ "@modern-js/server-core": "0.0.0-nightly-20240229170649"
92
92
  },
93
93
  "devDependencies": {
94
94
  "@rsbuild/plugin-swc": "0.4.8",
@@ -98,8 +98,8 @@
98
98
  "jest": "^29",
99
99
  "typescript": "^5",
100
100
  "webpack": "^5.89.0",
101
- "@scripts/build": "0.0.0-nightly-20240228170648",
102
- "@scripts/jest-config": "0.0.0-nightly-20240228170648"
101
+ "@scripts/build": "0.0.0-nightly-20240229170649",
102
+ "@scripts/jest-config": "0.0.0-nightly-20240229170649"
103
103
  },
104
104
  "sideEffects": false,
105
105
  "publishConfig": {