@utoo/web 1.0.7 → 1.2.0-rc.1
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/esm/aa0ad15d2a587c43406f.wasm +0 -0
- package/esm/internalProject.d.ts +1 -0
- package/esm/internalProject.js +10 -85
- package/esm/loaderWorker.js +2 -0
- package/esm/loaderWorker.js.LICENSE.txt +44 -0
- package/esm/loaderWorkerPool.d.ts +3 -0
- package/esm/loaderWorkerPool.js +125 -0
- package/esm/project.d.ts +1 -0
- package/esm/project.js +2 -0
- package/esm/sabcom.d.ts +31 -0
- package/esm/sabcom.js +71 -0
- package/esm/type.d.ts +1 -0
- package/esm/utoo/index.d.ts +71 -46
- package/esm/utoo/index.js +260 -168
- package/esm/utoo/index_bg.wasm +0 -0
- package/esm/webpackLoaders/loaders/less-loader/index.js +7 -12
- package/esm/webpackLoaders/loaders/less-loader/options.json +1 -3
- package/esm/webpackLoaders/loaders/less-loader/utils.js +14 -34
- package/esm/webpackLoaders/worker/cjs.js +253 -58
- package/esm/webpackLoaders/worker/index.d.ts +2 -2
- package/esm/webpackLoaders/worker/index.js +36 -26
- package/esm/webpackLoaders/worker/polyfills/fastGlobPolyfill.d.ts +2 -0
- package/esm/webpackLoaders/worker/polyfills/fastGlobPolyfill.js +48 -0
- package/esm/webpackLoaders/worker/polyfills/fsPolyfill.d.ts +124 -0
- package/esm/webpackLoaders/worker/polyfills/fsPolyfill.js +316 -0
- package/esm/webpackLoaders/worker/polyfills/fsPromisesPolyfill.d.ts +9 -0
- package/esm/webpackLoaders/worker/polyfills/fsPromisesPolyfill.js +9 -0
- package/esm/webpackLoaders/worker/polyfills/nodePolyFills.d.ts +94 -0
- package/esm/webpackLoaders/worker/polyfills/nodePolyFills.js +229 -0
- package/esm/webpackLoaders/worker/polyfills/workerThreadsPolyfill.d.ts +7 -0
- package/esm/webpackLoaders/worker/polyfills/workerThreadsPolyfill.js +16 -0
- package/esm/webpackLoaders/worker/type.d.ts +1 -1
- package/package.json +11 -11
- package/esm/webpackLoaders/worker/nodePolyFills.d.ts +0 -14
- package/esm/webpackLoaders/worker/nodePolyFills.js +0 -24
- package/esm/webpackLoaders/workerContent.d.ts +0 -2
- package/esm/webpackLoaders/workerContent.js +0 -1
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
3
|
+
value: true
|
|
4
4
|
});
|
|
5
5
|
exports.default = void 0;
|
|
6
6
|
var _path = _interopRequireDefault(require("path"));
|
|
7
7
|
var _options = _interopRequireDefault(require("./options.json"));
|
|
8
8
|
var _utils = require("./utils");
|
|
9
|
-
function _interopRequireDefault(e) {
|
|
10
|
-
return e && e.__esModule ? e : { default: e };
|
|
11
|
-
}
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
10
|
async function lessLoader(source) {
|
|
13
11
|
const options = this.getOptions(_options.default);
|
|
14
12
|
const callback = this.async();
|
|
@@ -28,15 +26,12 @@ async function lessLoader(source) {
|
|
|
28
26
|
const useSourceMap = typeof options.sourceMap === "boolean" ? options.sourceMap : this.sourceMap;
|
|
29
27
|
if (useSourceMap) {
|
|
30
28
|
lessOptions.sourceMap = {
|
|
31
|
-
outputSourceFiles: true
|
|
29
|
+
outputSourceFiles: true
|
|
32
30
|
};
|
|
33
31
|
}
|
|
34
32
|
let data = source;
|
|
35
33
|
if (typeof options.additionalData !== "undefined") {
|
|
36
|
-
data =
|
|
37
|
-
typeof options.additionalData === "function"
|
|
38
|
-
? `${await options.additionalData(data, this)}`
|
|
39
|
-
: `${options.additionalData}\n${data}`;
|
|
34
|
+
data = typeof options.additionalData === "function" ? `${await options.additionalData(data, this)}` : `${options.additionalData}\n${data}`;
|
|
40
35
|
}
|
|
41
36
|
const logger = this.getLogger("less-loader");
|
|
42
37
|
const loaderContext = this;
|
|
@@ -64,7 +59,7 @@ async function lessLoader(source) {
|
|
|
64
59
|
},
|
|
65
60
|
debug(message) {
|
|
66
61
|
logger.debug(message);
|
|
67
|
-
}
|
|
62
|
+
}
|
|
68
63
|
};
|
|
69
64
|
implementation.logger.addListener(loggerListener);
|
|
70
65
|
let result;
|
|
@@ -87,7 +82,7 @@ async function lessLoader(source) {
|
|
|
87
82
|
delete lessOptions.pluginManager;
|
|
88
83
|
}
|
|
89
84
|
const { css, imports } = result;
|
|
90
|
-
imports.forEach(
|
|
85
|
+
imports.forEach(item => {
|
|
91
86
|
if ((0, _utils.isUnsupportedUrl)(item)) {
|
|
92
87
|
return;
|
|
93
88
|
}
|
|
@@ -105,4 +100,4 @@ async function lessLoader(source) {
|
|
|
105
100
|
}
|
|
106
101
|
callback(null, css, map);
|
|
107
102
|
}
|
|
108
|
-
var _default =
|
|
103
|
+
var _default = exports.default = lessLoader;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const { type } = require("os");
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
4
|
+
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.errorFactory = errorFactory;
|
|
7
7
|
exports.getLessImplementation = getLessImplementation;
|
|
@@ -9,9 +9,7 @@ exports.getLessOptions = getLessOptions;
|
|
|
9
9
|
exports.isUnsupportedUrl = isUnsupportedUrl;
|
|
10
10
|
exports.normalizeSourceMap = normalizeSourceMap;
|
|
11
11
|
var _path = _interopRequireDefault(require("path"));
|
|
12
|
-
function _interopRequireDefault(e) {
|
|
13
|
-
return e && e.__esModule ? e : { default: e };
|
|
14
|
-
}
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
13
|
/* eslint-disable class-methods-use-this */
|
|
16
14
|
const trailingSlash = /[/\\]$/;
|
|
17
15
|
// This somewhat changed in Less 3.x. Now the file name comes without the
|
|
@@ -44,7 +42,7 @@ function createWebpackLessPlugin(loaderContext, implementation) {
|
|
|
44
42
|
mainFields: ["less", "style", "main", "..."],
|
|
45
43
|
mainFiles: ["index", "..."],
|
|
46
44
|
extensions: [".less", ".css"],
|
|
47
|
-
preferRelative: true
|
|
45
|
+
preferRelative: true
|
|
48
46
|
});
|
|
49
47
|
class WebpackFileManager extends implementation.FileManager {
|
|
50
48
|
supports(filename) {
|
|
@@ -97,8 +95,7 @@ function createWebpackLessPlugin(loaderContext, implementation) {
|
|
|
97
95
|
async loadFile(filename, ...args) {
|
|
98
96
|
let result;
|
|
99
97
|
try {
|
|
100
|
-
if (IS_SPECIAL_MODULE_IMPORT.test(filename) ||
|
|
101
|
-
lessOptions.webpackImporter === "only") {
|
|
98
|
+
if (IS_SPECIAL_MODULE_IMPORT.test(filename) || lessOptions.webpackImporter === "only") {
|
|
102
99
|
const error = new Error();
|
|
103
100
|
error.type = "Next";
|
|
104
101
|
throw error;
|
|
@@ -113,18 +110,13 @@ function createWebpackLessPlugin(loaderContext, implementation) {
|
|
|
113
110
|
result = await this.resolveFilename(filename, ...args);
|
|
114
111
|
}
|
|
115
112
|
catch (webpackResolveError) {
|
|
116
|
-
error.message =
|
|
117
|
-
`Less resolver error:\n${error.message}\n\n` +
|
|
118
|
-
`Webpack resolver error details:\n${webpackResolveError.details}\n\n` +
|
|
119
|
-
`Webpack resolver error missing:\n${webpackResolveError.missing}\n\n`;
|
|
113
|
+
error.message = `Less resolver error:\n${error.message}\n\n` + `Webpack resolver error details:\n${webpackResolveError.details}\n\n` + `Webpack resolver error missing:\n${webpackResolveError.missing}\n\n`;
|
|
120
114
|
return Promise.reject(error);
|
|
121
115
|
}
|
|
122
116
|
loaderContext.addDependency(result);
|
|
123
117
|
return super.loadFile(result, ...args);
|
|
124
118
|
}
|
|
125
|
-
const absoluteFilename = _path.default.isAbsolute(result.filename)
|
|
126
|
-
? result.filename
|
|
127
|
-
: _path.default.resolve(".", result.filename);
|
|
119
|
+
const absoluteFilename = _path.default.isAbsolute(result.filename) ? result.filename : _path.default.resolve(".", result.filename);
|
|
128
120
|
loaderContext.addDependency(_path.default.normalize(absoluteFilename));
|
|
129
121
|
return result;
|
|
130
122
|
}
|
|
@@ -133,7 +125,7 @@ function createWebpackLessPlugin(loaderContext, implementation) {
|
|
|
133
125
|
install(lessInstance, pluginManager) {
|
|
134
126
|
pluginManager.addFileManager(new WebpackFileManager());
|
|
135
127
|
},
|
|
136
|
-
minVersion: [3, 0, 0]
|
|
128
|
+
minVersion: [3, 0, 0]
|
|
137
129
|
};
|
|
138
130
|
}
|
|
139
131
|
/**
|
|
@@ -145,21 +137,16 @@ function createWebpackLessPlugin(loaderContext, implementation) {
|
|
|
145
137
|
* @returns {Object}
|
|
146
138
|
*/
|
|
147
139
|
function getLessOptions(loaderContext, loaderOptions, implementation) {
|
|
148
|
-
const options = typeof loaderOptions.lessOptions === "function"
|
|
149
|
-
? loaderOptions.lessOptions(loaderContext) || {}
|
|
150
|
-
: loaderOptions.lessOptions || {};
|
|
140
|
+
const options = typeof loaderOptions.lessOptions === "function" ? loaderOptions.lessOptions(loaderContext) || {} : loaderOptions.lessOptions || {};
|
|
151
141
|
const lessOptions = {
|
|
152
142
|
plugins: [],
|
|
153
143
|
relativeUrls: true,
|
|
154
144
|
// We need to set the filename because otherwise our WebpackFileManager will receive an undefined path for the entry
|
|
155
145
|
filename: loaderContext.resourcePath,
|
|
156
|
-
...options
|
|
146
|
+
...options
|
|
157
147
|
};
|
|
158
148
|
const plugins = lessOptions.plugins.slice();
|
|
159
|
-
const shouldUseWebpackImporter = typeof loaderOptions.webpackImporter === "boolean" ||
|
|
160
|
-
loaderOptions.webpackImporter === "only"
|
|
161
|
-
? loaderOptions.webpackImporter
|
|
162
|
-
: true;
|
|
149
|
+
const shouldUseWebpackImporter = typeof loaderOptions.webpackImporter === "boolean" || loaderOptions.webpackImporter === "only" ? loaderOptions.webpackImporter : true;
|
|
163
150
|
if (shouldUseWebpackImporter) {
|
|
164
151
|
plugins.unshift(createWebpackLessPlugin(loaderContext, implementation));
|
|
165
152
|
}
|
|
@@ -168,7 +155,7 @@ function getLessOptions(loaderContext, loaderOptions, implementation) {
|
|
|
168
155
|
// eslint-disable-next-line no-param-reassign
|
|
169
156
|
pluginManager.webpackLoaderContext = loaderContext;
|
|
170
157
|
lessOptions.pluginManager = pluginManager;
|
|
171
|
-
}
|
|
158
|
+
}
|
|
172
159
|
});
|
|
173
160
|
lessOptions.plugins = plugins;
|
|
174
161
|
return lessOptions;
|
|
@@ -192,7 +179,7 @@ function normalizeSourceMap(map) {
|
|
|
192
179
|
newMap.sourceRoot = "";
|
|
193
180
|
// `less` returns POSIX paths, that's why we need to transform them back to native paths.
|
|
194
181
|
// eslint-disable-next-line no-param-reassign
|
|
195
|
-
newMap.sources = newMap.sources.map(
|
|
182
|
+
newMap.sources = newMap.sources.map(source => _path.default.normalize(source));
|
|
196
183
|
return newMap;
|
|
197
184
|
}
|
|
198
185
|
function getLessImplementation(loaderContext, implementation) {
|
|
@@ -221,16 +208,9 @@ function getFileExcerptIfPossible(error) {
|
|
|
221
208
|
return excerpt;
|
|
222
209
|
}
|
|
223
210
|
function errorFactory(error) {
|
|
224
|
-
const message = [
|
|
225
|
-
"\n",
|
|
226
|
-
...getFileExcerptIfPossible(error),
|
|
227
|
-
error.message.charAt(0).toUpperCase() + error.message.slice(1),
|
|
228
|
-
error.filename
|
|
229
|
-
? ` Error in ${_path.default.normalize(error.filename)} (line ${error.line}, column ${error.column})`
|
|
230
|
-
: "",
|
|
231
|
-
].join("\n");
|
|
211
|
+
const message = ["\n", ...getFileExcerptIfPossible(error), error.message.charAt(0).toUpperCase() + error.message.slice(1), error.filename ? ` Error in ${_path.default.normalize(error.filename)} (line ${error.line}, column ${error.column})` : ""].join("\n");
|
|
232
212
|
const obj = new Error(message, {
|
|
233
|
-
cause: error
|
|
213
|
+
cause: error
|
|
234
214
|
});
|
|
235
215
|
obj.stack = null;
|
|
236
216
|
return obj;
|
|
@@ -1,9 +1,255 @@
|
|
|
1
1
|
import "systemjs/dist/system.js";
|
|
2
|
-
import nodePolyFills from "./nodePolyFills";
|
|
2
|
+
import nodePolyFills from "./polyfills/nodePolyFills";
|
|
3
|
+
const fs = nodePolyFills.fs;
|
|
4
|
+
const path = nodePolyFills.path;
|
|
5
|
+
const installedModules = {};
|
|
6
|
+
const statCache = {};
|
|
7
|
+
const pkgJsonCache = {};
|
|
8
|
+
const resolutionCache = {};
|
|
9
|
+
const searchPathsCache = {};
|
|
10
|
+
const statSync = (p) => {
|
|
11
|
+
if (p.includes("node_modules") &&
|
|
12
|
+
Object.prototype.hasOwnProperty.call(statCache, p)) {
|
|
13
|
+
if (statCache[p] === false)
|
|
14
|
+
throw new Error("ENOENT");
|
|
15
|
+
return statCache[p];
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const res = fs.statSync(p);
|
|
19
|
+
if (p.includes("node_modules"))
|
|
20
|
+
statCache[p] = res;
|
|
21
|
+
return res;
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
if (p.includes("node_modules"))
|
|
25
|
+
statCache[p] = false;
|
|
26
|
+
throw e;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const existsSync = (p) => {
|
|
30
|
+
try {
|
|
31
|
+
statSync(p);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
catch (_a) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const executeModule = (moduleCode, moduleId, id, importMaps, entrypoint) => {
|
|
39
|
+
if (installedModules[moduleId]) {
|
|
40
|
+
return installedModules[moduleId].exports;
|
|
41
|
+
}
|
|
42
|
+
const context = path.dirname(moduleId);
|
|
43
|
+
let finalExports = {};
|
|
44
|
+
const moduleRequire = (childId) => loadModule(childId, context, importMaps, entrypoint);
|
|
45
|
+
moduleRequire.resolve = (request) => request;
|
|
46
|
+
const module = { exports: finalExports, require: moduleRequire };
|
|
47
|
+
if (moduleId.includes("node_modules")) {
|
|
48
|
+
installedModules[moduleId] = module;
|
|
49
|
+
}
|
|
50
|
+
// Hack for entrypoint
|
|
51
|
+
if (moduleId === entrypoint) {
|
|
52
|
+
moduleCode = "self.Buffer = require('buffer').Buffer;" + moduleCode;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
if (moduleId.endsWith(".json")) {
|
|
56
|
+
finalExports = JSON.parse(moduleCode);
|
|
57
|
+
module.exports = finalExports;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
new Function("require", "exports", "module", "__filename", "__dirname", moduleCode)(moduleRequire, module.exports, module, moduleId, context);
|
|
61
|
+
finalExports = module.exports;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
console.error(`Worker: Error executing module ${moduleId}:`, e);
|
|
66
|
+
throw new Error(`Failed to load dependency ${moduleId}: ${e.message}`);
|
|
67
|
+
}
|
|
68
|
+
const originalWarn = console.warn;
|
|
69
|
+
console.warn = (...args) => {
|
|
70
|
+
var _a;
|
|
71
|
+
const msg = ((_a = args[0]) === null || _a === void 0 ? void 0 : _a.toString()) || "";
|
|
72
|
+
if (msg.includes("(SystemJS Error#W3")) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
originalWarn.apply(console, args);
|
|
76
|
+
};
|
|
77
|
+
try {
|
|
78
|
+
System.set(moduleId, { default: finalExports });
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
// ignore
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
console.warn = originalWarn;
|
|
85
|
+
}
|
|
86
|
+
return finalExports;
|
|
87
|
+
};
|
|
88
|
+
const loadModule = (id, context, importMaps, entrypoint) => {
|
|
89
|
+
var _a, _b, _c, _d, _e, _f;
|
|
90
|
+
const cacheKey = `${context}:${id}`;
|
|
91
|
+
if (resolutionCache[cacheKey]) {
|
|
92
|
+
const cachedId = resolutionCache[cacheKey];
|
|
93
|
+
if (installedModules[cachedId]) {
|
|
94
|
+
return installedModules[cachedId].exports;
|
|
95
|
+
}
|
|
96
|
+
// Fast path: if we know the resolved path, try to load it directly
|
|
97
|
+
try {
|
|
98
|
+
const moduleCode = fs.readFileSync(cachedId, "utf8");
|
|
99
|
+
return executeModule(moduleCode, cachedId, id, importMaps, entrypoint);
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
// If read fails, fall back to full resolution
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// 1. Resolve
|
|
106
|
+
let resolvedId = id;
|
|
107
|
+
if (id.startsWith(".")) {
|
|
108
|
+
resolvedId = path.resolve(context, id);
|
|
109
|
+
}
|
|
110
|
+
// 2. Check Cache (SystemJS)
|
|
111
|
+
let dependency = System.get(resolvedId);
|
|
112
|
+
if (dependency)
|
|
113
|
+
return dependency.default;
|
|
114
|
+
if (id !== resolvedId) {
|
|
115
|
+
dependency = System.get(id);
|
|
116
|
+
if (dependency)
|
|
117
|
+
return dependency.default;
|
|
118
|
+
}
|
|
119
|
+
// 3. Check Node Polyfills
|
|
120
|
+
if (id in nodePolyFills) {
|
|
121
|
+
// @ts-ignore
|
|
122
|
+
return nodePolyFills[id];
|
|
123
|
+
}
|
|
124
|
+
if (resolvedId in nodePolyFills) {
|
|
125
|
+
// @ts-ignore
|
|
126
|
+
return nodePolyFills[resolvedId];
|
|
127
|
+
}
|
|
128
|
+
// 4. Check importMaps & FS
|
|
129
|
+
let moduleCode = importMaps[resolvedId] || importMaps[id];
|
|
130
|
+
let moduleId = importMaps[resolvedId] ? resolvedId : id;
|
|
131
|
+
// Fallback: Try resolving from node_modules
|
|
132
|
+
if (!moduleCode && !id.startsWith(".") && !id.startsWith("/")) {
|
|
133
|
+
let searchPaths = searchPathsCache[context];
|
|
134
|
+
if (!searchPaths) {
|
|
135
|
+
searchPaths = [];
|
|
136
|
+
// @ts-ignore
|
|
137
|
+
const cwd = ((_b = (_a = self.process) === null || _a === void 0 ? void 0 : _a.cwd) === null || _b === void 0 ? void 0 : _b.call(_a)) || ((_c = self.workerData) === null || _c === void 0 ? void 0 : _c.cwd) || "/";
|
|
138
|
+
const isInsideNodeModules = context.includes("/node_modules/") ||
|
|
139
|
+
context.includes("\\node_modules\\");
|
|
140
|
+
if (isInsideNodeModules) {
|
|
141
|
+
searchPaths.push(path.join(cwd, "node_modules"));
|
|
142
|
+
}
|
|
143
|
+
let currentDir = context;
|
|
144
|
+
while (true) {
|
|
145
|
+
if (path.basename(currentDir) !== "node_modules") {
|
|
146
|
+
const nodeModulesPath = path.join(currentDir, "node_modules");
|
|
147
|
+
if (!searchPaths.includes(nodeModulesPath)) {
|
|
148
|
+
searchPaths.push(nodeModulesPath);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const parent = path.dirname(currentDir);
|
|
152
|
+
if (parent === currentDir)
|
|
153
|
+
break;
|
|
154
|
+
currentDir = parent;
|
|
155
|
+
}
|
|
156
|
+
searchPathsCache[context] = searchPaths;
|
|
157
|
+
}
|
|
158
|
+
for (const nodeModulesDir of searchPaths) {
|
|
159
|
+
const nodeModulesPath = path.join(nodeModulesDir, id);
|
|
160
|
+
// Check package.json first
|
|
161
|
+
const pkgJsonPath = path.join(nodeModulesPath, "package.json");
|
|
162
|
+
if (existsSync(pkgJsonPath)) {
|
|
163
|
+
try {
|
|
164
|
+
let pkg;
|
|
165
|
+
if (pkgJsonCache[pkgJsonPath]) {
|
|
166
|
+
pkg = pkgJsonCache[pkgJsonPath];
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
|
|
170
|
+
pkgJsonCache[pkgJsonPath] = pkg;
|
|
171
|
+
}
|
|
172
|
+
const mainField = pkg.main;
|
|
173
|
+
if (mainField) {
|
|
174
|
+
const candidates = [
|
|
175
|
+
path.resolve(nodeModulesPath, mainField),
|
|
176
|
+
path.resolve(nodeModulesPath, mainField) + ".js",
|
|
177
|
+
path.resolve(nodeModulesPath, mainField) + ".json",
|
|
178
|
+
path.resolve(nodeModulesPath, mainField, "index.js"),
|
|
179
|
+
];
|
|
180
|
+
for (const candidate of candidates) {
|
|
181
|
+
if (existsSync(candidate) && !statSync(candidate).isDirectory()) {
|
|
182
|
+
resolvedId = candidate;
|
|
183
|
+
moduleCode = fs.readFileSync(candidate, "utf8");
|
|
184
|
+
moduleId = candidate;
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
catch (_g) { }
|
|
191
|
+
}
|
|
192
|
+
if (!moduleCode) {
|
|
193
|
+
const extensions = ["", ".js", ".json", "/index.js"];
|
|
194
|
+
for (const ext of extensions) {
|
|
195
|
+
const p = nodeModulesPath + ext;
|
|
196
|
+
if (existsSync(p) && !statSync(p).isDirectory()) {
|
|
197
|
+
resolvedId = p;
|
|
198
|
+
moduleCode = fs.readFileSync(p, "utf8");
|
|
199
|
+
moduleId = p;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (moduleCode)
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// Fallback: Try resolving absolute path (handling CWD stripping)
|
|
209
|
+
if (!moduleCode && id.startsWith("/")) {
|
|
210
|
+
// @ts-ignore
|
|
211
|
+
const cwd = ((_e = (_d = self.process) === null || _d === void 0 ? void 0 : _d.cwd) === null || _e === void 0 ? void 0 : _e.call(_d)) || ((_f = self.workerData) === null || _f === void 0 ? void 0 : _f.cwd) || "/";
|
|
212
|
+
let relativeId = id;
|
|
213
|
+
if (id.startsWith(cwd)) {
|
|
214
|
+
relativeId = id.slice(cwd.length);
|
|
215
|
+
if (relativeId.startsWith("/"))
|
|
216
|
+
relativeId = relativeId.slice(1);
|
|
217
|
+
}
|
|
218
|
+
const extensions = ["", ".js", ".json", "/index.js"];
|
|
219
|
+
for (const ext of extensions) {
|
|
220
|
+
const p = relativeId + ext;
|
|
221
|
+
if (existsSync(p) && !statSync(p).isDirectory()) {
|
|
222
|
+
resolvedId = p; // Use relative path for FS ops
|
|
223
|
+
moduleCode = fs.readFileSync(p, "utf8");
|
|
224
|
+
moduleId = id; // Keep original absolute path as module ID
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (!moduleCode) {
|
|
230
|
+
// Try extensions
|
|
231
|
+
const extensions = ["", ".js", ".json", "/index.js"];
|
|
232
|
+
for (const ext of extensions) {
|
|
233
|
+
const p = resolvedId + ext;
|
|
234
|
+
if (existsSync(p) && !statSync(p).isDirectory()) {
|
|
235
|
+
resolvedId = p;
|
|
236
|
+
moduleCode = fs.readFileSync(p, "utf8");
|
|
237
|
+
moduleId = p;
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (moduleCode) {
|
|
243
|
+
const cacheKey = `${context}:${id}`;
|
|
244
|
+
resolutionCache[cacheKey] = moduleId;
|
|
245
|
+
return executeModule(moduleCode, moduleId, id, importMaps, entrypoint);
|
|
246
|
+
}
|
|
247
|
+
console.error(`Worker: Dependency ${id} (resolved: ${resolvedId}) not found.`);
|
|
248
|
+
return {};
|
|
249
|
+
};
|
|
3
250
|
export async function cjs(entrypoint, importMaps) {
|
|
4
|
-
debugger;
|
|
5
251
|
await Promise.all(Object.entries(importMaps).map(async ([k, v]) => {
|
|
6
|
-
if (v.startsWith("
|
|
252
|
+
if (v.startsWith("https://")) {
|
|
7
253
|
try {
|
|
8
254
|
const response = await fetch(v);
|
|
9
255
|
if (response.ok) {
|
|
@@ -20,61 +266,10 @@ export async function cjs(entrypoint, importMaps) {
|
|
|
20
266
|
}
|
|
21
267
|
}
|
|
22
268
|
}));
|
|
23
|
-
Object.assign(importMaps, nodePolyFills);
|
|
24
|
-
const require = (id) => {
|
|
25
|
-
let dependency = System.get(id);
|
|
26
|
-
if (dependency) {
|
|
27
|
-
return dependency.default;
|
|
28
|
-
}
|
|
29
|
-
if (id in nodePolyFills) {
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
return nodePolyFills[id];
|
|
32
|
-
}
|
|
33
|
-
const moduleCode = importMaps[id];
|
|
34
|
-
if (!moduleCode) {
|
|
35
|
-
console.error(`Worker: Dependency ${id} not found in import maps.`);
|
|
36
|
-
return {};
|
|
37
|
-
}
|
|
38
|
-
let finalExports = {};
|
|
39
|
-
const module = { exports: finalExports };
|
|
40
|
-
const exports = module.exports;
|
|
41
|
-
try {
|
|
42
|
-
new Function("require", "exports", "module", moduleCode)(require, exports, module);
|
|
43
|
-
finalExports = module.exports;
|
|
44
|
-
}
|
|
45
|
-
catch (e) {
|
|
46
|
-
console.error(`Worker: Error executing dependency module ${id}:`, e);
|
|
47
|
-
throw new Error(`Failed to load CJS dependency ${id}: ${e.message}`);
|
|
48
|
-
}
|
|
49
|
-
System.set(id, { default: finalExports });
|
|
50
|
-
return finalExports;
|
|
51
|
-
};
|
|
52
|
-
require.resolve = (request) => request;
|
|
53
269
|
// @ts-ignore
|
|
54
270
|
// a hack for loader-runner resolving
|
|
55
|
-
self.__systemjs_require__ =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (path === entrypoint) {
|
|
60
|
-
entryPointCode = moduleCode;
|
|
61
|
-
// FIXME
|
|
62
|
-
entryPointCode = "self.Buffer = require('buffer').Buffer;" + moduleCode;
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (entryPointCode) {
|
|
67
|
-
let finalExports = {};
|
|
68
|
-
const module = { exports: finalExports };
|
|
69
|
-
const exports = module.exports;
|
|
70
|
-
try {
|
|
71
|
-
new Function("require", "exports", "module", entryPointCode)(require, exports, module);
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
74
|
-
console.error(`Worker: Error executing entry point ${entrypoint}:`, e);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
console.warn("Warning: Entry point not found in import maps. No final execution step taken.");
|
|
79
|
-
}
|
|
271
|
+
self.__systemjs_require__ = (id) => loadModule(id, path.dirname(entrypoint), importMaps, entrypoint);
|
|
272
|
+
// @ts-ignore
|
|
273
|
+
self.__systemjs_require__.resolve = (request) => request;
|
|
274
|
+
loadModule(entrypoint, path.dirname(entrypoint), importMaps, entrypoint);
|
|
80
275
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare
|
|
2
|
-
export default
|
|
1
|
+
export declare function startLoaderWorker(): void;
|
|
2
|
+
export default startLoaderWorker;
|
|
@@ -1,31 +1,41 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SabComClient } from "../../sabcom";
|
|
2
|
+
import initWasm, { recvTaskMessageInWorker, sendTaskMessage, workerCreated, } from "../../utoo";
|
|
2
3
|
import { cjs } from "./cjs";
|
|
3
4
|
const binding = {
|
|
4
|
-
|
|
5
|
-
recvMessageInWorker,
|
|
6
|
-
notifyWorkerAck,
|
|
5
|
+
recvTaskMessageInWorker,
|
|
7
6
|
sendTaskMessage,
|
|
7
|
+
workerCreated,
|
|
8
8
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
9
|
+
export function startLoaderWorker() {
|
|
10
|
+
self.onmessage = async (event) => {
|
|
11
|
+
let [module, memory, meta] = event.data;
|
|
12
|
+
await initWasm(module, memory).catch((err) => {
|
|
13
|
+
console.log(err);
|
|
14
|
+
throw err;
|
|
15
|
+
});
|
|
16
|
+
const sabClient = meta.sab
|
|
17
|
+
? new SabComClient(meta.sab, () => {
|
|
18
|
+
self.postMessage("sab_request");
|
|
19
|
+
})
|
|
20
|
+
: undefined;
|
|
21
|
+
self.workerData = {
|
|
22
|
+
workerId: meta.workerData.workerId,
|
|
23
|
+
cwd: meta.workerData.cwd,
|
|
24
|
+
binding,
|
|
25
|
+
sabClient,
|
|
26
|
+
};
|
|
27
|
+
self.process = {
|
|
28
|
+
env: {},
|
|
29
|
+
cwd: () => self.workerData.cwd,
|
|
30
|
+
};
|
|
31
|
+
console.log("Worker CWD:", self.process.cwd());
|
|
32
|
+
cjs(meta.loaderAssets.entrypoint, meta.loaderAssets.importMaps);
|
|
28
33
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
}
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
if (typeof __webpack_require__ !== "undefined") {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
self.startLoaderWorker = startLoaderWorker;
|
|
39
|
+
}
|
|
40
|
+
startLoaderWorker();
|
|
41
|
+
export default startLoaderWorker;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import micromatch from "micromatch";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import * as fs from "./fsPolyfill";
|
|
4
|
+
const walkSync = (currentDir, rootDir, entries) => {
|
|
5
|
+
let list;
|
|
6
|
+
try {
|
|
7
|
+
list = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
8
|
+
}
|
|
9
|
+
catch (e) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
for (const entry of list) {
|
|
13
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
14
|
+
const relativePath = path.relative(rootDir, fullPath);
|
|
15
|
+
if (entry.isDirectory()) {
|
|
16
|
+
walkSync(fullPath, rootDir, entries);
|
|
17
|
+
}
|
|
18
|
+
else if (entry.isFile()) {
|
|
19
|
+
entries.push(relativePath);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const fastGlob = (patterns, options = {}) => {
|
|
24
|
+
return Promise.resolve(fastGlob.sync(patterns, options));
|
|
25
|
+
};
|
|
26
|
+
fastGlob.sync = (patterns, options = {}) => {
|
|
27
|
+
const cwd = options.cwd || "/";
|
|
28
|
+
const ignore = options.ignore || [];
|
|
29
|
+
const allFiles = [];
|
|
30
|
+
walkSync(cwd, cwd, allFiles);
|
|
31
|
+
const matched = micromatch(allFiles, patterns, {
|
|
32
|
+
ignore: ignore,
|
|
33
|
+
dot: options.dot,
|
|
34
|
+
cwd: cwd,
|
|
35
|
+
});
|
|
36
|
+
if (options.absolute) {
|
|
37
|
+
return matched.map((p) => path.join(cwd, p));
|
|
38
|
+
}
|
|
39
|
+
return matched;
|
|
40
|
+
};
|
|
41
|
+
fastGlob.stream = (patterns, options = {}) => {
|
|
42
|
+
throw new Error("fastGlob.stream is not implemented in polyfill");
|
|
43
|
+
};
|
|
44
|
+
fastGlob.async = fastGlob;
|
|
45
|
+
fastGlob.generateTasks = () => [];
|
|
46
|
+
fastGlob.isDynamicPattern = (p) => micromatch.scan(p).isGlob;
|
|
47
|
+
fastGlob.escapePath = (p) => p.replace(/([*?|(){}[\]])/g, "\\$1");
|
|
48
|
+
export default fastGlob;
|