@module-federation/nextjs-mf 5.3.2 → 5.4.0
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.
- package/lib/ModuleFederationPlugin.js +3 -1
- package/lib/NextFederationPlugin.js +18 -1051
- package/lib/_virtual/_commonjsHelpers.js +44 -0
- package/lib/_virtual/_path.js +11 -0
- package/lib/_virtual/_tslib.js +176 -0
- package/lib/_virtual/fs.js +7 -0
- package/lib/_virtual/fs2.js +7 -0
- package/lib/_virtual/options.js +7 -0
- package/lib/_virtual/utils.js +7 -0
- package/lib/client/MFClient.d.ts +4 -1
- package/lib/client/MFClient.d.ts.map +1 -1
- package/lib/client/MFClient.js +35 -19
- package/lib/client/RemoteContainer.js +1 -0
- package/lib/client/RemotePages.d.ts +2 -1
- package/lib/client/RemotePages.d.ts.map +1 -1
- package/lib/client/RemotePages.js +38 -12
- package/lib/dependencies/webpack/lib/container/options.js +102 -0
- package/lib/dependencies/webpack/lib/sharing/utils.js +104 -0
- package/lib/dependencies/webpack/lib/util/fs.js +359 -0
- package/lib/internal.js +35 -18
- package/lib/loaders/UrlNode.js +3 -1
- package/lib/loaders/patchNextClientPageLoader.js +1 -1
- package/lib/node-plugin/streaming/CommonJsChunkLoadingPlugin.js +92 -0
- package/lib/node-plugin/streaming/LoadFileChunkLoadingRuntimeModule.js +412 -0
- package/lib/node-plugin/streaming/NodeRuntime.js +247 -0
- package/lib/node-plugin/streaming/index.js +44 -0
- package/lib/node-plugin/streaming/loadScript.js +57 -0
- package/lib/plugins/DevHmrFixInvalidPongPlugin.js +14 -0
- package/lib/utils.js +16 -7
- package/package.json +4 -3
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('../../../../_virtual/_commonjsHelpers.js');
|
|
6
|
+
var utils = require('../../../../_virtual/utils.js');
|
|
7
|
+
require('../../../../_virtual/fs.js');
|
|
8
|
+
var fs = require('../../../../_virtual/fs2.js');
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
12
|
+
Author Tobias Koppers @sokra
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
"use strict";
|
|
16
|
+
|
|
17
|
+
const { join, dirname, readJson } = fs.__exports;
|
|
18
|
+
|
|
19
|
+
/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {string} str maybe required version
|
|
23
|
+
* @returns {boolean} true, if it looks like a version
|
|
24
|
+
*/
|
|
25
|
+
var isRequiredVersion = utils.__exports.isRequiredVersion = str => {
|
|
26
|
+
return /^([\d^=v<>~]|[*xX]$)/.test(str);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param {InputFileSystem} fs file system
|
|
32
|
+
* @param {string} directory directory to start looking into
|
|
33
|
+
* @param {string[]} descriptionFiles possible description filenames
|
|
34
|
+
* @param {function(Error=, {data: object, path: string}=): void} callback callback
|
|
35
|
+
*/
|
|
36
|
+
const getDescriptionFile = (fs, directory, descriptionFiles, callback) => {
|
|
37
|
+
let i = 0;
|
|
38
|
+
const tryLoadCurrent = () => {
|
|
39
|
+
if (i >= descriptionFiles.length) {
|
|
40
|
+
const parentDirectory = dirname(fs, directory);
|
|
41
|
+
if (!parentDirectory || parentDirectory === directory) return callback();
|
|
42
|
+
return getDescriptionFile(
|
|
43
|
+
fs,
|
|
44
|
+
parentDirectory,
|
|
45
|
+
descriptionFiles,
|
|
46
|
+
callback
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
const filePath = join(fs, directory, descriptionFiles[i]);
|
|
50
|
+
readJson(fs, filePath, (err, data) => {
|
|
51
|
+
if (err) {
|
|
52
|
+
if ("code" in err && err.code === "ENOENT") {
|
|
53
|
+
i++;
|
|
54
|
+
return tryLoadCurrent();
|
|
55
|
+
}
|
|
56
|
+
return callback(err);
|
|
57
|
+
}
|
|
58
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) {
|
|
59
|
+
return callback(
|
|
60
|
+
new Error(`Description file ${filePath} is not an object`)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
callback(null, { data, path: filePath });
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
tryLoadCurrent();
|
|
67
|
+
};
|
|
68
|
+
var getDescriptionFile_1 = utils.__exports.getDescriptionFile = getDescriptionFile;
|
|
69
|
+
|
|
70
|
+
var getRequiredVersionFromDescriptionFile = utils.__exports.getRequiredVersionFromDescriptionFile = (data, packageName) => {
|
|
71
|
+
if (
|
|
72
|
+
data.optionalDependencies &&
|
|
73
|
+
typeof data.optionalDependencies === "object" &&
|
|
74
|
+
packageName in data.optionalDependencies
|
|
75
|
+
) {
|
|
76
|
+
return data.optionalDependencies[packageName];
|
|
77
|
+
}
|
|
78
|
+
if (
|
|
79
|
+
data.dependencies &&
|
|
80
|
+
typeof data.dependencies === "object" &&
|
|
81
|
+
packageName in data.dependencies
|
|
82
|
+
) {
|
|
83
|
+
return data.dependencies[packageName];
|
|
84
|
+
}
|
|
85
|
+
if (
|
|
86
|
+
data.peerDependencies &&
|
|
87
|
+
typeof data.peerDependencies === "object" &&
|
|
88
|
+
packageName in data.peerDependencies
|
|
89
|
+
) {
|
|
90
|
+
return data.peerDependencies[packageName];
|
|
91
|
+
}
|
|
92
|
+
if (
|
|
93
|
+
data.devDependencies &&
|
|
94
|
+
typeof data.devDependencies === "object" &&
|
|
95
|
+
packageName in data.devDependencies
|
|
96
|
+
) {
|
|
97
|
+
return data.devDependencies[packageName];
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
exports["default"] = utils.__exports;
|
|
102
|
+
exports.getDescriptionFile = getDescriptionFile_1;
|
|
103
|
+
exports.getRequiredVersionFromDescriptionFile = getRequiredVersionFromDescriptionFile;
|
|
104
|
+
exports.isRequiredVersion = isRequiredVersion;
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('../../../../_virtual/_commonjsHelpers.js');
|
|
6
|
+
var fs = require('../../../../_virtual/fs2.js');
|
|
7
|
+
require('../../../../_virtual/_path.js');
|
|
8
|
+
var path$1 = require('path');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
+
|
|
12
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path$1);
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
16
|
+
Author Tobias Koppers @sokra
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
const path = path__default["default"];
|
|
22
|
+
|
|
23
|
+
/** @typedef {import("../../declarations/WebpackOptions").WatchOptions} WatchOptions */
|
|
24
|
+
/** @typedef {import("../FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {Object} IStats
|
|
28
|
+
* @property {() => boolean} isFile
|
|
29
|
+
* @property {() => boolean} isDirectory
|
|
30
|
+
* @property {() => boolean} isBlockDevice
|
|
31
|
+
* @property {() => boolean} isCharacterDevice
|
|
32
|
+
* @property {() => boolean} isSymbolicLink
|
|
33
|
+
* @property {() => boolean} isFIFO
|
|
34
|
+
* @property {() => boolean} isSocket
|
|
35
|
+
* @property {number | bigint} dev
|
|
36
|
+
* @property {number | bigint} ino
|
|
37
|
+
* @property {number | bigint} mode
|
|
38
|
+
* @property {number | bigint} nlink
|
|
39
|
+
* @property {number | bigint} uid
|
|
40
|
+
* @property {number | bigint} gid
|
|
41
|
+
* @property {number | bigint} rdev
|
|
42
|
+
* @property {number | bigint} size
|
|
43
|
+
* @property {number | bigint} blksize
|
|
44
|
+
* @property {number | bigint} blocks
|
|
45
|
+
* @property {number | bigint} atimeMs
|
|
46
|
+
* @property {number | bigint} mtimeMs
|
|
47
|
+
* @property {number | bigint} ctimeMs
|
|
48
|
+
* @property {number | bigint} birthtimeMs
|
|
49
|
+
* @property {Date} atime
|
|
50
|
+
* @property {Date} mtime
|
|
51
|
+
* @property {Date} ctime
|
|
52
|
+
* @property {Date} birthtime
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @typedef {Object} IDirent
|
|
57
|
+
* @property {() => boolean} isFile
|
|
58
|
+
* @property {() => boolean} isDirectory
|
|
59
|
+
* @property {() => boolean} isBlockDevice
|
|
60
|
+
* @property {() => boolean} isCharacterDevice
|
|
61
|
+
* @property {() => boolean} isSymbolicLink
|
|
62
|
+
* @property {() => boolean} isFIFO
|
|
63
|
+
* @property {() => boolean} isSocket
|
|
64
|
+
* @property {string | Buffer} name
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=): void} Callback */
|
|
68
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=, Buffer=): void} BufferCallback */
|
|
69
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=, Buffer|string=): void} BufferOrStringCallback */
|
|
70
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=, (string | Buffer)[] | IDirent[]=): void} DirentArrayCallback */
|
|
71
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=, string=): void} StringCallback */
|
|
72
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=, number=): void} NumberCallback */
|
|
73
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=, IStats=): void} StatsCallback */
|
|
74
|
+
/** @typedef {function((NodeJS.ErrnoException | Error | null)=, any=): void} ReadJsonCallback */
|
|
75
|
+
/** @typedef {function((NodeJS.ErrnoException | Error | null)=, IStats|string=): void} LstatReadlinkAbsoluteCallback */
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @typedef {Object} WatcherInfo
|
|
79
|
+
* @property {Set<string>} changes get current aggregated changes that have not yet send to callback
|
|
80
|
+
* @property {Set<string>} removals get current aggregated removals that have not yet send to callback
|
|
81
|
+
* @property {Map<string, FileSystemInfoEntry | "ignore">} fileTimeInfoEntries get info about files
|
|
82
|
+
* @property {Map<string, FileSystemInfoEntry | "ignore">} contextTimeInfoEntries get info about directories
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
// TODO webpack 6 deprecate missing getInfo
|
|
86
|
+
/**
|
|
87
|
+
* @typedef {Object} Watcher
|
|
88
|
+
* @property {function(): void} close closes the watcher and all underlying file watchers
|
|
89
|
+
* @property {function(): void} pause closes the watcher, but keeps underlying file watchers alive until the next watch call
|
|
90
|
+
* @property {function(): Set<string>=} getAggregatedChanges get current aggregated changes that have not yet send to callback
|
|
91
|
+
* @property {function(): Set<string>=} getAggregatedRemovals get current aggregated removals that have not yet send to callback
|
|
92
|
+
* @property {function(): Map<string, FileSystemInfoEntry | "ignore">} getFileTimeInfoEntries get info about files
|
|
93
|
+
* @property {function(): Map<string, FileSystemInfoEntry | "ignore">} getContextTimeInfoEntries get info about directories
|
|
94
|
+
* @property {function(): WatcherInfo=} getInfo get info about timestamps and changes
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @callback WatchMethod
|
|
99
|
+
* @param {Iterable<string>} files watched files
|
|
100
|
+
* @param {Iterable<string>} directories watched directories
|
|
101
|
+
* @param {Iterable<string>} missing watched exitance entries
|
|
102
|
+
* @param {number} startTime timestamp of start time
|
|
103
|
+
* @param {WatchOptions} options options object
|
|
104
|
+
* @param {function(Error=, Map<string, FileSystemInfoEntry | "ignore">, Map<string, FileSystemInfoEntry | "ignore">, Set<string>, Set<string>): void} callback aggregated callback
|
|
105
|
+
* @param {function(string, number): void} callbackUndelayed callback when the first change was detected
|
|
106
|
+
* @returns {Watcher} a watcher
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
// TODO webpack 6 make optional methods required
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @typedef {Object} OutputFileSystem
|
|
113
|
+
* @property {function(string, Buffer|string, Callback): void} writeFile
|
|
114
|
+
* @property {function(string, Callback): void} mkdir
|
|
115
|
+
* @property {function(string, DirentArrayCallback): void=} readdir
|
|
116
|
+
* @property {function(string, Callback): void=} rmdir
|
|
117
|
+
* @property {function(string, Callback): void=} unlink
|
|
118
|
+
* @property {function(string, StatsCallback): void} stat
|
|
119
|
+
* @property {function(string, StatsCallback): void=} lstat
|
|
120
|
+
* @property {function(string, BufferOrStringCallback): void} readFile
|
|
121
|
+
* @property {(function(string, string): string)=} join
|
|
122
|
+
* @property {(function(string, string): string)=} relative
|
|
123
|
+
* @property {(function(string): string)=} dirname
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @typedef {Object} InputFileSystem
|
|
128
|
+
* @property {function(string, BufferOrStringCallback): void} readFile
|
|
129
|
+
* @property {(function(string, ReadJsonCallback): void)=} readJson
|
|
130
|
+
* @property {function(string, BufferOrStringCallback): void} readlink
|
|
131
|
+
* @property {function(string, DirentArrayCallback): void} readdir
|
|
132
|
+
* @property {function(string, StatsCallback): void} stat
|
|
133
|
+
* @property {function(string, StatsCallback): void=} lstat
|
|
134
|
+
* @property {(function(string, BufferOrStringCallback): void)=} realpath
|
|
135
|
+
* @property {(function(string=): void)=} purge
|
|
136
|
+
* @property {(function(string, string): string)=} join
|
|
137
|
+
* @property {(function(string, string): string)=} relative
|
|
138
|
+
* @property {(function(string): string)=} dirname
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @typedef {Object} WatchFileSystem
|
|
143
|
+
* @property {WatchMethod} watch
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* @typedef {Object} IntermediateFileSystemExtras
|
|
148
|
+
* @property {function(string): void} mkdirSync
|
|
149
|
+
* @property {function(string): NodeJS.WritableStream} createWriteStream
|
|
150
|
+
* @property {function(string, string, NumberCallback): void} open
|
|
151
|
+
* @property {function(number, Buffer, number, number, number, NumberCallback): void} read
|
|
152
|
+
* @property {function(number, Callback): void} close
|
|
153
|
+
* @property {function(string, string, Callback): void} rename
|
|
154
|
+
*/
|
|
155
|
+
|
|
156
|
+
/** @typedef {InputFileSystem & OutputFileSystem & IntermediateFileSystemExtras} IntermediateFileSystem */
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
*
|
|
160
|
+
* @param {InputFileSystem|OutputFileSystem|undefined} fs a file system
|
|
161
|
+
* @param {string} rootPath the root path
|
|
162
|
+
* @param {string} targetPath the target path
|
|
163
|
+
* @returns {string} location of targetPath relative to rootPath
|
|
164
|
+
*/
|
|
165
|
+
const relative = (fs, rootPath, targetPath) => {
|
|
166
|
+
if (fs && fs.relative) {
|
|
167
|
+
return fs.relative(rootPath, targetPath);
|
|
168
|
+
} else if (path.posix.isAbsolute(rootPath)) {
|
|
169
|
+
return path.posix.relative(rootPath, targetPath);
|
|
170
|
+
} else if (path.win32.isAbsolute(rootPath)) {
|
|
171
|
+
return path.win32.relative(rootPath, targetPath);
|
|
172
|
+
} else {
|
|
173
|
+
throw new Error(
|
|
174
|
+
`${rootPath} is neither a posix nor a windows path, and there is no 'relative' method defined in the file system`
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
var relative_1 = fs.__exports.relative = relative;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @param {InputFileSystem|OutputFileSystem|undefined} fs a file system
|
|
182
|
+
* @param {string} rootPath a path
|
|
183
|
+
* @param {string} filename a filename
|
|
184
|
+
* @returns {string} the joined path
|
|
185
|
+
*/
|
|
186
|
+
const join = (fs, rootPath, filename) => {
|
|
187
|
+
if (fs && fs.join) {
|
|
188
|
+
return fs.join(rootPath, filename);
|
|
189
|
+
} else if (path.posix.isAbsolute(rootPath)) {
|
|
190
|
+
return path.posix.join(rootPath, filename);
|
|
191
|
+
} else if (path.win32.isAbsolute(rootPath)) {
|
|
192
|
+
return path.win32.join(rootPath, filename);
|
|
193
|
+
} else {
|
|
194
|
+
throw new Error(
|
|
195
|
+
`${rootPath} is neither a posix nor a windows path, and there is no 'join' method defined in the file system`
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
var join_1 = fs.__exports.join = join;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @param {InputFileSystem|OutputFileSystem|undefined} fs a file system
|
|
203
|
+
* @param {string} absPath an absolute path
|
|
204
|
+
* @returns {string} the parent directory of the absolute path
|
|
205
|
+
*/
|
|
206
|
+
const dirname = (fs, absPath) => {
|
|
207
|
+
if (fs && fs.dirname) {
|
|
208
|
+
return fs.dirname(absPath);
|
|
209
|
+
} else if (path.posix.isAbsolute(absPath)) {
|
|
210
|
+
return path.posix.dirname(absPath);
|
|
211
|
+
} else if (path.win32.isAbsolute(absPath)) {
|
|
212
|
+
return path.win32.dirname(absPath);
|
|
213
|
+
} else {
|
|
214
|
+
throw new Error(
|
|
215
|
+
`${absPath} is neither a posix nor a windows path, and there is no 'dirname' method defined in the file system`
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
var dirname_1 = fs.__exports.dirname = dirname;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* @param {OutputFileSystem} fs a file system
|
|
223
|
+
* @param {string} p an absolute path
|
|
224
|
+
* @param {function(Error=): void} callback callback function for the error
|
|
225
|
+
* @returns {void}
|
|
226
|
+
*/
|
|
227
|
+
const mkdirp = (fs, p, callback) => {
|
|
228
|
+
fs.mkdir(p, err => {
|
|
229
|
+
if (err) {
|
|
230
|
+
if (err.code === "ENOENT") {
|
|
231
|
+
const dir = dirname(fs, p);
|
|
232
|
+
if (dir === p) {
|
|
233
|
+
callback(err);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
mkdirp(fs, dir, err => {
|
|
237
|
+
if (err) {
|
|
238
|
+
callback(err);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
fs.mkdir(p, err => {
|
|
242
|
+
if (err) {
|
|
243
|
+
if (err.code === "EEXIST") {
|
|
244
|
+
callback();
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
callback(err);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
callback();
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
return;
|
|
254
|
+
} else if (err.code === "EEXIST") {
|
|
255
|
+
callback();
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
callback(err);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
callback();
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
var mkdirp_1 = fs.__exports.mkdirp = mkdirp;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* @param {IntermediateFileSystem} fs a file system
|
|
268
|
+
* @param {string} p an absolute path
|
|
269
|
+
* @returns {void}
|
|
270
|
+
*/
|
|
271
|
+
const mkdirpSync = (fs, p) => {
|
|
272
|
+
try {
|
|
273
|
+
fs.mkdirSync(p);
|
|
274
|
+
} catch (err) {
|
|
275
|
+
if (err) {
|
|
276
|
+
if (err.code === "ENOENT") {
|
|
277
|
+
const dir = dirname(fs, p);
|
|
278
|
+
if (dir === p) {
|
|
279
|
+
throw err;
|
|
280
|
+
}
|
|
281
|
+
mkdirpSync(fs, dir);
|
|
282
|
+
fs.mkdirSync(p);
|
|
283
|
+
return;
|
|
284
|
+
} else if (err.code === "EEXIST") {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
throw err;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
var mkdirpSync_1 = fs.__exports.mkdirpSync = mkdirpSync;
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* @param {InputFileSystem} fs a file system
|
|
295
|
+
* @param {string} p an absolute path
|
|
296
|
+
* @param {ReadJsonCallback} callback callback
|
|
297
|
+
* @returns {void}
|
|
298
|
+
*/
|
|
299
|
+
const readJson = (fs, p, callback) => {
|
|
300
|
+
if ("readJson" in fs) return fs.readJson(p, callback);
|
|
301
|
+
fs.readFile(p, (err, buf) => {
|
|
302
|
+
if (err) return callback(err);
|
|
303
|
+
let data;
|
|
304
|
+
try {
|
|
305
|
+
data = JSON.parse(buf.toString("utf-8"));
|
|
306
|
+
} catch (e) {
|
|
307
|
+
return callback(e);
|
|
308
|
+
}
|
|
309
|
+
return callback(null, data);
|
|
310
|
+
});
|
|
311
|
+
};
|
|
312
|
+
var readJson_1 = fs.__exports.readJson = readJson;
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* @param {InputFileSystem} fs a file system
|
|
316
|
+
* @param {string} p an absolute path
|
|
317
|
+
* @param {ReadJsonCallback} callback callback
|
|
318
|
+
* @returns {void}
|
|
319
|
+
*/
|
|
320
|
+
const lstatReadlinkAbsolute = (fs, p, callback) => {
|
|
321
|
+
let i = 3;
|
|
322
|
+
const doReadLink = () => {
|
|
323
|
+
fs.readlink(p, (err, target) => {
|
|
324
|
+
if (err && --i > 0) {
|
|
325
|
+
// It might was just changed from symlink to file
|
|
326
|
+
// we retry 2 times to catch this case before throwing the error
|
|
327
|
+
return doStat();
|
|
328
|
+
}
|
|
329
|
+
if (err || !target) return doStat();
|
|
330
|
+
const value = target.toString();
|
|
331
|
+
callback(null, join(fs, dirname(fs, p), value));
|
|
332
|
+
});
|
|
333
|
+
};
|
|
334
|
+
const doStat = () => {
|
|
335
|
+
if ("lstat" in fs) {
|
|
336
|
+
return fs.lstat(p, (err, stats) => {
|
|
337
|
+
if (err) return callback(err);
|
|
338
|
+
if (stats.isSymbolicLink()) {
|
|
339
|
+
return doReadLink();
|
|
340
|
+
}
|
|
341
|
+
callback(null, stats);
|
|
342
|
+
});
|
|
343
|
+
} else {
|
|
344
|
+
return fs.stat(p, callback);
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
if ("lstat" in fs) return doStat();
|
|
348
|
+
doReadLink();
|
|
349
|
+
};
|
|
350
|
+
var lstatReadlinkAbsolute_1 = fs.__exports.lstatReadlinkAbsolute = lstatReadlinkAbsolute;
|
|
351
|
+
|
|
352
|
+
exports["default"] = fs.__exports;
|
|
353
|
+
exports.dirname = dirname_1;
|
|
354
|
+
exports.join = join_1;
|
|
355
|
+
exports.lstatReadlinkAbsolute = lstatReadlinkAbsolute_1;
|
|
356
|
+
exports.mkdirp = mkdirp_1;
|
|
357
|
+
exports.mkdirpSync = mkdirpSync_1;
|
|
358
|
+
exports.readJson = readJson_1;
|
|
359
|
+
exports.relative = relative_1;
|
package/lib/internal.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var options = require('./dependencies/webpack/lib/container/options.js');
|
|
6
|
+
var utils = require('./dependencies/webpack/lib/sharing/utils.js');
|
|
7
|
+
var path = require('path');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
4
12
|
|
|
5
13
|
// the share scope we attach by default
|
|
6
14
|
// in hosts we re-key them to prevent webpack moving the modules into their own chunks (cause eager error)
|
|
7
15
|
// in remote these are marked as import:false as we always expect the host to prove them
|
|
8
|
-
|
|
16
|
+
const DEFAULT_SHARE_SCOPE = {
|
|
9
17
|
react: {
|
|
10
18
|
singleton: true,
|
|
11
19
|
requiredVersion: false,
|
|
@@ -44,7 +52,7 @@ export const DEFAULT_SHARE_SCOPE = {
|
|
|
44
52
|
},
|
|
45
53
|
};
|
|
46
54
|
// put host infront of any shared module key, so "hostreact"
|
|
47
|
-
|
|
55
|
+
const reKeyHostShared = (options) => {
|
|
48
56
|
return Object.entries({
|
|
49
57
|
...(options || {}),
|
|
50
58
|
...DEFAULT_SHARE_SCOPE,
|
|
@@ -68,7 +76,7 @@ export const reKeyHostShared = (options) => {
|
|
|
68
76
|
};
|
|
69
77
|
|
|
70
78
|
// split the @ syntax into url and global
|
|
71
|
-
|
|
79
|
+
const extractUrlAndGlobal = (urlAndGlobal) => {
|
|
72
80
|
const index = urlAndGlobal.indexOf('@');
|
|
73
81
|
if (index <= 0 || index === urlAndGlobal.length - 1) {
|
|
74
82
|
throw new Error(`Invalid request "${urlAndGlobal}"`);
|
|
@@ -77,7 +85,7 @@ export const extractUrlAndGlobal = (urlAndGlobal) => {
|
|
|
77
85
|
};
|
|
78
86
|
|
|
79
87
|
// browser template to convert remote into promise new promise and use require.loadChunk to load the chunk
|
|
80
|
-
|
|
88
|
+
const generateRemoteTemplate = (url, global) => {
|
|
81
89
|
return `promise new Promise(function (resolve, reject) {
|
|
82
90
|
var __webpack_error__ = new Error();
|
|
83
91
|
if (typeof ${global} !== 'undefined') return resolve();
|
|
@@ -132,17 +140,17 @@ export const generateRemoteTemplate = (url, global) => {
|
|
|
132
140
|
}
|
|
133
141
|
return proxy
|
|
134
142
|
})`;
|
|
135
|
-
}
|
|
143
|
+
};
|
|
136
144
|
|
|
137
|
-
const parseShareOptions = (options) => {
|
|
138
|
-
const sharedOptions = parseOptions(
|
|
139
|
-
options.shared,
|
|
145
|
+
const parseShareOptions = (options$1) => {
|
|
146
|
+
const sharedOptions = options.parseOptions(
|
|
147
|
+
options$1.shared,
|
|
140
148
|
(item, key) => {
|
|
141
149
|
if (typeof item !== 'string')
|
|
142
150
|
throw new Error('Unexpected array in shared');
|
|
143
151
|
/** @type {SharedConfig} */
|
|
144
152
|
const config =
|
|
145
|
-
item === key || !isRequiredVersion(item)
|
|
153
|
+
item === key || !utils.isRequiredVersion(item)
|
|
146
154
|
? {
|
|
147
155
|
import: item,
|
|
148
156
|
}
|
|
@@ -170,7 +178,7 @@ const parseShareOptions = (options) => {
|
|
|
170
178
|
};
|
|
171
179
|
|
|
172
180
|
// shared packages must be compiled into webpack bundle, not require() pass through
|
|
173
|
-
|
|
181
|
+
const internalizeSharedPackages = (options, compiler) => {
|
|
174
182
|
//TODO: should use this util for other areas where we read MF options from userland
|
|
175
183
|
if (!options.shared) {
|
|
176
184
|
return;
|
|
@@ -200,7 +208,7 @@ export const internalizeSharedPackages = (options, compiler) => {
|
|
|
200
208
|
}
|
|
201
209
|
};
|
|
202
210
|
|
|
203
|
-
|
|
211
|
+
const externalizedShares = Object.entries(DEFAULT_SHARE_SCOPE).reduce(
|
|
204
212
|
(acc, item) => {
|
|
205
213
|
const [key, value] = item;
|
|
206
214
|
acc[key] = { ...value, import: false };
|
|
@@ -213,20 +221,20 @@ export const externalizedShares = Object.entries(DEFAULT_SHARE_SCOPE).reduce(
|
|
|
213
221
|
);
|
|
214
222
|
|
|
215
223
|
// determine output base path, derives .next folder location
|
|
216
|
-
|
|
224
|
+
const getOutputPath = (compiler) => {
|
|
217
225
|
const isServer = compiler.options.target !== 'client';
|
|
218
|
-
let outputPath = compiler.options.output.path.split(
|
|
226
|
+
let outputPath = compiler.options.output.path.split(path__default["default"].sep);
|
|
219
227
|
const foundIndex = outputPath.findIndex((i) => {
|
|
220
228
|
return i === (isServer ? 'server' : 'static');
|
|
221
229
|
});
|
|
222
230
|
outputPath = outputPath
|
|
223
231
|
.slice(0, foundIndex > 0 ? foundIndex : outputPath.length)
|
|
224
|
-
.join(
|
|
232
|
+
.join(path__default["default"].sep);
|
|
225
233
|
|
|
226
234
|
return outputPath;
|
|
227
235
|
};
|
|
228
236
|
|
|
229
|
-
|
|
237
|
+
const removePlugins = [
|
|
230
238
|
'NextJsRequireCacheHotReloader',
|
|
231
239
|
'BuildManifestPlugin',
|
|
232
240
|
'WellKnownErrorsPlugin',
|
|
@@ -239,3 +247,12 @@ export const removePlugins = [
|
|
|
239
247
|
'DropClientPage',
|
|
240
248
|
'ReactFreshWebpackPlugin',
|
|
241
249
|
];
|
|
250
|
+
|
|
251
|
+
exports.DEFAULT_SHARE_SCOPE = DEFAULT_SHARE_SCOPE;
|
|
252
|
+
exports.externalizedShares = externalizedShares;
|
|
253
|
+
exports.extractUrlAndGlobal = extractUrlAndGlobal;
|
|
254
|
+
exports.generateRemoteTemplate = generateRemoteTemplate;
|
|
255
|
+
exports.getOutputPath = getOutputPath;
|
|
256
|
+
exports.internalizeSharedPackages = internalizeSharedPackages;
|
|
257
|
+
exports.reKeyHostShared = reKeyHostShared;
|
|
258
|
+
exports.removePlugins = removePlugins;
|
package/lib/loaders/UrlNode.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* It was copied from
|
|
16
16
|
* @see https://github.com/vercel/next.js/blob/canary/packages/next/shared/lib/router/utils/sorted-routes.ts
|
|
17
17
|
*/
|
|
18
|
-
|
|
18
|
+
class UrlNode {
|
|
19
19
|
placeholder = true;
|
|
20
20
|
children = new Map();
|
|
21
21
|
slugName = null;
|
|
@@ -207,3 +207,5 @@ export class UrlNode {
|
|
|
207
207
|
._insert(urlPaths.slice(1), slugNames, isCatchAll);
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
+
|
|
211
|
+
module.exports = { UrlNode };
|
|
@@ -32,7 +32,7 @@ function patchNextClientPageLoader(content) {
|
|
|
32
32
|
class PageLoaderExtended extends PageLoader {
|
|
33
33
|
constructor(buildId, assetPrefix) {
|
|
34
34
|
super(buildId, assetPrefix);
|
|
35
|
-
global.mf_client = new MFClient(this);
|
|
35
|
+
global.mf_client = new MFClient(this, { mode: process.env.NODE_ENV });
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
_getPageListOriginal() {
|