@utoo/web 1.0.0 → 1.0.2
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/internalProject.d.ts +29 -0
- package/esm/internalProject.js +185 -0
- package/esm/project.d.ts +3 -2
- package/esm/project.js +4 -4
- package/esm/threadWorker.js +0 -6
- package/esm/type.d.ts +4 -2
- package/esm/utoo/index.d.ts +78 -0
- package/esm/utoo/index.js +248 -83
- package/esm/utoo/index_bg.wasm +0 -0
- package/esm/webpackLoaders/loaders/lessLoader/index.d.ts +3 -0
- package/esm/webpackLoaders/loaders/lessLoader/index.js +103 -0
- package/esm/webpackLoaders/loaders/lessLoader/options.json +67 -0
- package/esm/webpackLoaders/loaders/lessLoader/utils.d.ts +14 -0
- package/esm/webpackLoaders/loaders/lessLoader/utils.js +217 -0
- package/esm/webpackLoaders/worker/cjs.d.ts +2 -0
- package/esm/webpackLoaders/worker/cjs.js +77 -0
- package/esm/webpackLoaders/worker/index.d.ts +2 -0
- package/esm/webpackLoaders/worker/index.js +31 -0
- package/esm/webpackLoaders/worker/nodePolyFills.d.ts +14 -0
- package/esm/webpackLoaders/worker/nodePolyFills.js +24 -0
- package/esm/webpackLoaders/worker/type.d.ts +11 -0
- package/esm/webpackLoaders/worker/type.js +1 -0
- package/esm/webpackLoaders/workerContent.d.ts +2 -0
- package/esm/webpackLoaders/workerContent.js +1 -0
- package/esm/worker.js +2 -109
- package/package.json +15 -5
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const __esModule: boolean;
|
|
2
|
+
export function errorFactory(error: any): Error;
|
|
3
|
+
export function getLessImplementation(loaderContext: any, implementation: any): any;
|
|
4
|
+
/**
|
|
5
|
+
* Get the `less` options from the loader context and normalizes its values
|
|
6
|
+
*
|
|
7
|
+
* @param {object} loaderContext
|
|
8
|
+
* @param {object} loaderOptions
|
|
9
|
+
* @param {object} implementation
|
|
10
|
+
* @returns {Object}
|
|
11
|
+
*/
|
|
12
|
+
export function getLessOptions(loaderContext: object, loaderOptions: object, implementation: object): Object;
|
|
13
|
+
export function isUnsupportedUrl(url: any): boolean;
|
|
14
|
+
export function normalizeSourceMap(map: any): any;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { type } = require("os");
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.errorFactory = errorFactory;
|
|
7
|
+
exports.getLessImplementation = getLessImplementation;
|
|
8
|
+
exports.getLessOptions = getLessOptions;
|
|
9
|
+
exports.isUnsupportedUrl = isUnsupportedUrl;
|
|
10
|
+
exports.normalizeSourceMap = normalizeSourceMap;
|
|
11
|
+
var _path = _interopRequireDefault(require("path"));
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
/* eslint-disable class-methods-use-this */
|
|
14
|
+
const trailingSlash = /[/\\]$/;
|
|
15
|
+
// This somewhat changed in Less 3.x. Now the file name comes without the
|
|
16
|
+
// automatically added extension whereas the extension is passed in as `options.ext`.
|
|
17
|
+
// So, if the file name matches this regexp, we simply ignore the proposed extension.
|
|
18
|
+
const IS_SPECIAL_MODULE_IMPORT = /^~[^/]+$/;
|
|
19
|
+
// `[drive_letter]:\` + `\\[server]\[share_name]\`
|
|
20
|
+
const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i;
|
|
21
|
+
// Examples:
|
|
22
|
+
// - ~package
|
|
23
|
+
// - ~package/
|
|
24
|
+
// - ~@org
|
|
25
|
+
// - ~@org/
|
|
26
|
+
// - ~@org/package
|
|
27
|
+
// - ~@org/package/
|
|
28
|
+
const IS_MODULE_IMPORT = /^~([^/]+|[^/]+\/|@[^/]+[/][^/]+|@[^/]+\/?|@[^/]+[/][^/]+\/)$/;
|
|
29
|
+
const MODULE_REQUEST_REGEX = /^[^?]*~/;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a Less plugin that uses webpack's resolving engine that is provided by the loaderContext.
|
|
32
|
+
*
|
|
33
|
+
* @param {LoaderContext} loaderContext
|
|
34
|
+
* @param {object} implementation
|
|
35
|
+
* @returns {LessPlugin}
|
|
36
|
+
*/
|
|
37
|
+
function createWebpackLessPlugin(loaderContext, implementation) {
|
|
38
|
+
const lessOptions = loaderContext.getOptions();
|
|
39
|
+
const resolve = loaderContext.getResolve({
|
|
40
|
+
dependencyType: "less",
|
|
41
|
+
conditionNames: ["less", "style", "..."],
|
|
42
|
+
mainFields: ["less", "style", "main", "..."],
|
|
43
|
+
mainFiles: ["index", "..."],
|
|
44
|
+
extensions: [".less", ".css"],
|
|
45
|
+
preferRelative: true
|
|
46
|
+
});
|
|
47
|
+
class WebpackFileManager extends implementation.FileManager {
|
|
48
|
+
supports(filename) {
|
|
49
|
+
if (filename[0] === "/" || IS_NATIVE_WIN32_PATH.test(filename)) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if (this.isPathAbsolute(filename)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
// Sync resolving is used at least by the `data-uri` function.
|
|
58
|
+
// This file manager doesn't know how to do it, so let's delegate it
|
|
59
|
+
// to the default file manager of Less.
|
|
60
|
+
// We could probably use loaderContext.resolveSync, but it's deprecated,
|
|
61
|
+
// see https://webpack.js.org/api/loaders/#this-resolvesync
|
|
62
|
+
supportsSync() {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
async resolveFilename(filename, currentDirectory) {
|
|
66
|
+
// Less is giving us trailing slashes, but the context should have no trailing slash
|
|
67
|
+
const context = currentDirectory.replace(trailingSlash, "");
|
|
68
|
+
let request = filename;
|
|
69
|
+
// A `~` makes the url an module
|
|
70
|
+
if (MODULE_REQUEST_REGEX.test(filename)) {
|
|
71
|
+
request = request.replace(MODULE_REQUEST_REGEX, "");
|
|
72
|
+
}
|
|
73
|
+
if (IS_MODULE_IMPORT.test(filename)) {
|
|
74
|
+
request = request[request.length - 1] === "/" ? request : `${request}/`;
|
|
75
|
+
}
|
|
76
|
+
return this.resolveRequests(context, [...new Set([request, filename])]);
|
|
77
|
+
}
|
|
78
|
+
async resolveRequests(context, possibleRequests) {
|
|
79
|
+
if (possibleRequests.length === 0) {
|
|
80
|
+
return Promise.reject();
|
|
81
|
+
}
|
|
82
|
+
let result;
|
|
83
|
+
try {
|
|
84
|
+
result = await resolve(context, possibleRequests[0]);
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
const [, ...tailPossibleRequests] = possibleRequests;
|
|
88
|
+
if (tailPossibleRequests.length === 0) {
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
result = await this.resolveRequests(context, tailPossibleRequests);
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
async loadFile(filename, ...args) {
|
|
96
|
+
let result;
|
|
97
|
+
try {
|
|
98
|
+
if (IS_SPECIAL_MODULE_IMPORT.test(filename) || lessOptions.webpackImporter === "only") {
|
|
99
|
+
const error = new Error();
|
|
100
|
+
error.type = "Next";
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
result = await super.loadFile(filename, ...args);
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (error.type !== "File" && error.type !== "Next") {
|
|
107
|
+
return Promise.reject(error);
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
result = await this.resolveFilename(filename, ...args);
|
|
111
|
+
}
|
|
112
|
+
catch (webpackResolveError) {
|
|
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`;
|
|
114
|
+
return Promise.reject(error);
|
|
115
|
+
}
|
|
116
|
+
loaderContext.addDependency(result);
|
|
117
|
+
return super.loadFile(result, ...args);
|
|
118
|
+
}
|
|
119
|
+
const absoluteFilename = _path.default.isAbsolute(result.filename) ? result.filename : _path.default.resolve(".", result.filename);
|
|
120
|
+
loaderContext.addDependency(_path.default.normalize(absoluteFilename));
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
install(lessInstance, pluginManager) {
|
|
126
|
+
pluginManager.addFileManager(new WebpackFileManager());
|
|
127
|
+
},
|
|
128
|
+
minVersion: [3, 0, 0]
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get the `less` options from the loader context and normalizes its values
|
|
133
|
+
*
|
|
134
|
+
* @param {object} loaderContext
|
|
135
|
+
* @param {object} loaderOptions
|
|
136
|
+
* @param {object} implementation
|
|
137
|
+
* @returns {Object}
|
|
138
|
+
*/
|
|
139
|
+
function getLessOptions(loaderContext, loaderOptions, implementation) {
|
|
140
|
+
const options = typeof loaderOptions.lessOptions === "function" ? loaderOptions.lessOptions(loaderContext) || {} : loaderOptions.lessOptions || {};
|
|
141
|
+
const lessOptions = {
|
|
142
|
+
plugins: [],
|
|
143
|
+
relativeUrls: true,
|
|
144
|
+
// We need to set the filename because otherwise our WebpackFileManager will receive an undefined path for the entry
|
|
145
|
+
filename: loaderContext.resourcePath,
|
|
146
|
+
...options
|
|
147
|
+
};
|
|
148
|
+
const plugins = lessOptions.plugins.slice();
|
|
149
|
+
const shouldUseWebpackImporter = typeof loaderOptions.webpackImporter === "boolean" || loaderOptions.webpackImporter === "only" ? loaderOptions.webpackImporter : true;
|
|
150
|
+
if (shouldUseWebpackImporter) {
|
|
151
|
+
plugins.unshift(createWebpackLessPlugin(loaderContext, implementation));
|
|
152
|
+
}
|
|
153
|
+
plugins.unshift({
|
|
154
|
+
install(lessProcessor, pluginManager) {
|
|
155
|
+
// eslint-disable-next-line no-param-reassign
|
|
156
|
+
pluginManager.webpackLoaderContext = loaderContext;
|
|
157
|
+
lessOptions.pluginManager = pluginManager;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
lessOptions.plugins = plugins;
|
|
161
|
+
return lessOptions;
|
|
162
|
+
}
|
|
163
|
+
function isUnsupportedUrl(url) {
|
|
164
|
+
// Is Windows path
|
|
165
|
+
if (IS_NATIVE_WIN32_PATH.test(url)) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
// Scheme: https://tools.ietf.org/html/rfc3986#section-3.1
|
|
169
|
+
// Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3
|
|
170
|
+
return /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(url);
|
|
171
|
+
}
|
|
172
|
+
function normalizeSourceMap(map) {
|
|
173
|
+
const newMap = map;
|
|
174
|
+
// map.file is an optional property that provides the output filename.
|
|
175
|
+
// Since we don't know the final filename in the webpack build chain yet, it makes no sense to have it.
|
|
176
|
+
// eslint-disable-next-line no-param-reassign
|
|
177
|
+
delete newMap.file;
|
|
178
|
+
// eslint-disable-next-line no-param-reassign
|
|
179
|
+
newMap.sourceRoot = "";
|
|
180
|
+
// `less` returns POSIX paths, that's why we need to transform them back to native paths.
|
|
181
|
+
// eslint-disable-next-line no-param-reassign
|
|
182
|
+
newMap.sources = newMap.sources.map(source => _path.default.normalize(source));
|
|
183
|
+
return newMap;
|
|
184
|
+
}
|
|
185
|
+
function getLessImplementation(loaderContext, implementation) {
|
|
186
|
+
let resolvedImplementation = implementation;
|
|
187
|
+
if (!implementation) {
|
|
188
|
+
// eslint-disable-next-line import/no-dynamic-require, global-require
|
|
189
|
+
resolvedImplementation = require("less/lib/less-node/index.js").default;
|
|
190
|
+
}
|
|
191
|
+
else if (typeof implementation === "string") {
|
|
192
|
+
// eslint-disable-next-line import/no-dynamic-require, global-require
|
|
193
|
+
resolvedImplementation = require(implementation);
|
|
194
|
+
}
|
|
195
|
+
// eslint-disable-next-line consistent-return
|
|
196
|
+
return resolvedImplementation;
|
|
197
|
+
}
|
|
198
|
+
function getFileExcerptIfPossible(error) {
|
|
199
|
+
if (typeof error.extract === "undefined") {
|
|
200
|
+
return [];
|
|
201
|
+
}
|
|
202
|
+
const excerpt = error.extract.slice(0, 2);
|
|
203
|
+
const column = Math.max(error.column - 1, 0);
|
|
204
|
+
if (typeof excerpt[0] === "undefined") {
|
|
205
|
+
excerpt.shift();
|
|
206
|
+
}
|
|
207
|
+
excerpt.push(`${new Array(column).join(" ")}^`);
|
|
208
|
+
return excerpt;
|
|
209
|
+
}
|
|
210
|
+
function errorFactory(error) {
|
|
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");
|
|
212
|
+
const obj = new Error(message, {
|
|
213
|
+
cause: error
|
|
214
|
+
});
|
|
215
|
+
obj.stack = null;
|
|
216
|
+
return obj;
|
|
217
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import "systemjs/dist/system.js";
|
|
2
|
+
import nodePolyFills from "./nodePolyFills";
|
|
3
|
+
export async function cjs(entrypoint, importMaps) {
|
|
4
|
+
debugger;
|
|
5
|
+
await Promise.all(Object.entries(importMaps).map(async ([k, v]) => {
|
|
6
|
+
if (v.startsWith("http")) {
|
|
7
|
+
try {
|
|
8
|
+
const response = await fetch(v);
|
|
9
|
+
if (response.ok) {
|
|
10
|
+
importMaps[k] = await response.text();
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
console.error(`Failed to fetch loader '${k}' from ${v}: ${response.status} ${response.statusText}`);
|
|
14
|
+
delete importMaps[k];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.error(`Error fetching loader '${k}' from ${v}:`, error);
|
|
19
|
+
delete importMaps[k];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}));
|
|
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
|
+
let entryPointCode;
|
|
54
|
+
for (const path in importMaps) {
|
|
55
|
+
const moduleCode = importMaps[path];
|
|
56
|
+
if (path === entrypoint) {
|
|
57
|
+
entryPointCode = moduleCode;
|
|
58
|
+
// FIXME
|
|
59
|
+
entryPointCode = "self.Buffer = require('buffer').Buffer;" + moduleCode;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (entryPointCode) {
|
|
64
|
+
let finalExports = {};
|
|
65
|
+
const module = { exports: finalExports };
|
|
66
|
+
const exports = module.exports;
|
|
67
|
+
try {
|
|
68
|
+
new Function("require", "exports", "module", entryPointCode)(require, exports, module);
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
console.error(`Worker: Error executing entry point ${entrypoint}:`, e);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
console.warn("Warning: Entry point not found in import maps. No final execution step taken.");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { cjs } from "./cjs";
|
|
2
|
+
import initWasm, { recvMessageInWorker, recvWorkerRequest, sendTaskMessage, notifyWorkerAck } from "../../utoo";
|
|
3
|
+
const binding = {
|
|
4
|
+
recvWorkerRequest,
|
|
5
|
+
recvMessageInWorker,
|
|
6
|
+
notifyWorkerAck,
|
|
7
|
+
sendTaskMessage
|
|
8
|
+
};
|
|
9
|
+
self.process = {
|
|
10
|
+
env: {},
|
|
11
|
+
cwd: () => self.workerData.cwd
|
|
12
|
+
};
|
|
13
|
+
self.onmessage = async (event) => {
|
|
14
|
+
let [module, memory, meta] = event.data;
|
|
15
|
+
await initWasm(module, memory).catch((err) => {
|
|
16
|
+
console.log(err);
|
|
17
|
+
throw err;
|
|
18
|
+
});
|
|
19
|
+
self.workerData = {
|
|
20
|
+
poolId: meta.workerData.poolId,
|
|
21
|
+
workerId: meta.workerData.workerId,
|
|
22
|
+
cwd: "./",
|
|
23
|
+
binding,
|
|
24
|
+
readFile: async (path) => {
|
|
25
|
+
// TODO: if we want that, just connect to @utoo/web internalProject endpoint port with comlink
|
|
26
|
+
throw new Error('readFile in loader not supported on browser ');
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
cjs(meta.loaderAssets.entrypoint, meta.loaderAssets.importMaps);
|
|
30
|
+
};
|
|
31
|
+
export default null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
assert: any;
|
|
3
|
+
buffer: any;
|
|
4
|
+
constants: any;
|
|
5
|
+
fs: {
|
|
6
|
+
readFile(path: string, options: any, cb: Function): any;
|
|
7
|
+
};
|
|
8
|
+
path: any;
|
|
9
|
+
url: any;
|
|
10
|
+
util: any;
|
|
11
|
+
less: any;
|
|
12
|
+
"less-loader": any;
|
|
13
|
+
};
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
const buffer = require('buffer');
|
|
3
|
+
const constants = require('constants');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const url = require('url');
|
|
6
|
+
const util = require('util');
|
|
7
|
+
const less = require("less/lib/less-node/index.js").default;
|
|
8
|
+
const lessLoader = require("../loaders/lessLoader");
|
|
9
|
+
export default {
|
|
10
|
+
assert,
|
|
11
|
+
buffer,
|
|
12
|
+
constants,
|
|
13
|
+
fs: {
|
|
14
|
+
readFile(path, options, cb) {
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
return self.workerData.readFile(path, options).then((data) => cb(null, data), (err) => cb(err));
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
path,
|
|
20
|
+
url,
|
|
21
|
+
util,
|
|
22
|
+
less,
|
|
23
|
+
"less-loader": lessLoader
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|