@loaders.gl/worker-utils 4.0.0-beta.4 → 4.0.0-beta.6
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Module from 'module';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
4
|
export async function readFileAsArrayBuffer(filename) {
|
|
5
5
|
if (filename.startsWith('http')) {
|
|
6
6
|
const response = await fetch(filename);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"require-utils.node.js","names":["Module","path","fs","readFileAsArrayBuffer","filename","startsWith","response","fetch","arrayBuffer","buffer","readFileSync","readFileAsText","text","requireFromFile","code","requireFromString","process","cwd","_module","_options","_options2","arguments","length","undefined","options","Error","paths","_nodeModulePaths","dirname","parent","module","newModule","concat","prependPaths","appendPaths","_compile","children","splice","indexOf","exports"],"sources":["../../../src/lib/node/require-utils.node.ts"],"sourcesContent":["// Fork of https://github.com/floatdrop/require-from-string/blob/master/index.js\n// Copyright (c) Vsevolod Strukchinsky <floatdrop@gmail.com> (github.com/floatdrop)\n// MIT license\n\n// this file is not visible to webpack (it is excluded in the package.json \"browser\" field).\n\nimport Module from 'module';\nimport path from 'path';\nimport fs from 'fs';\n\n/**\n * Load a file from local file system\n * @param filename\n * @returns\n */\nexport async function readFileAsArrayBuffer(filename: string): Promise<ArrayBuffer> {\n if (filename.startsWith('http')) {\n const response = await fetch(filename);\n return await response.arrayBuffer();\n }\n const buffer = fs.readFileSync(filename);\n return buffer.buffer;\n}\n\n/**\n * Load a file from local file system\n * @param filename\n * @returns\n */\nexport async function readFileAsText(filename: string): Promise<string> {\n if (filename.startsWith('http')) {\n const response = await fetch(filename);\n return await response.text();\n }\n const text = fs.readFileSync(filename, 'utf8');\n return text;\n}\n\n// Node.js Dynamically require from file\n// Relative names are resolved relative to cwd\n// This indirect function is provided because webpack will try to bundle `module.require`.\n// this file is not visible to webpack (it is excluded in the package.json \"browser\" field).\nexport async function requireFromFile(filename: string): Promise<any> {\n if (filename.startsWith('http')) {\n const response = await fetch(filename);\n const code = await response.text();\n return requireFromString(code);\n }\n\n if (!filename.startsWith('/')) {\n filename = `${process.cwd()}/${filename}`;\n }\n const code = await fs.readFileSync(filename, 'utf8');\n return requireFromString(code);\n}\n\n// Dynamically require from string\n// - `code` - Required - Type: string - Module code.\n// - `filename` - Type: string - Default: '' - Optional filename.\n// - `options.appendPaths` Type: Array List of paths, that will be appended to module paths.\n// Useful, when you want to be able require modules from these paths.\n// - `options.prependPaths` Type: Array Same as appendPaths, but paths will be prepended.\nexport function requireFromString(\n code: string,\n filename = '',\n options?: {\n prependPaths?: string[];\n appendPaths?: string[];\n }\n): any {\n if (typeof filename === 'object') {\n options = filename;\n filename = '';\n }\n\n if (typeof code !== 'string') {\n throw new Error(`code must be a string, not ${typeof code}`);\n }\n\n // @ts-ignore\n const paths = Module._nodeModulePaths(path.dirname(filename));\n\n const parent = typeof module !== 'undefined' && module?.parent;\n\n // @ts-ignore\n const newModule = new Module(filename, parent);\n newModule.filename = filename;\n newModule.paths = ([] as string[])\n .concat(options?.prependPaths || [])\n .concat(paths)\n .concat(options?.appendPaths || []);\n // @ts-ignore\n newModule._compile(code, filename);\n\n if (parent && parent.children) {\n parent.children.splice(parent.children.indexOf(newModule), 1);\n }\n\n return newModule.exports;\n}\n"],"mappings":"AAMA,OAAOA,MAAM,MAAM,QAAQ;AAC3B,
|
|
1
|
+
{"version":3,"file":"require-utils.node.js","names":["Module","path","fs","readFileAsArrayBuffer","filename","startsWith","response","fetch","arrayBuffer","buffer","readFileSync","readFileAsText","text","requireFromFile","code","requireFromString","process","cwd","_module","_options","_options2","arguments","length","undefined","options","Error","paths","_nodeModulePaths","dirname","parent","module","newModule","concat","prependPaths","appendPaths","_compile","children","splice","indexOf","exports"],"sources":["../../../src/lib/node/require-utils.node.ts"],"sourcesContent":["// Fork of https://github.com/floatdrop/require-from-string/blob/master/index.js\n// Copyright (c) Vsevolod Strukchinsky <floatdrop@gmail.com> (github.com/floatdrop)\n// MIT license\n\n// this file is not visible to webpack (it is excluded in the package.json \"browser\" field).\n\nimport Module from 'module';\nimport * as path from 'path';\nimport * as fs from 'fs';\n\n/**\n * Load a file from local file system\n * @param filename\n * @returns\n */\nexport async function readFileAsArrayBuffer(filename: string): Promise<ArrayBuffer> {\n if (filename.startsWith('http')) {\n const response = await fetch(filename);\n return await response.arrayBuffer();\n }\n const buffer = fs.readFileSync(filename);\n return buffer.buffer;\n}\n\n/**\n * Load a file from local file system\n * @param filename\n * @returns\n */\nexport async function readFileAsText(filename: string): Promise<string> {\n if (filename.startsWith('http')) {\n const response = await fetch(filename);\n return await response.text();\n }\n const text = fs.readFileSync(filename, 'utf8');\n return text;\n}\n\n// Node.js Dynamically require from file\n// Relative names are resolved relative to cwd\n// This indirect function is provided because webpack will try to bundle `module.require`.\n// this file is not visible to webpack (it is excluded in the package.json \"browser\" field).\nexport async function requireFromFile(filename: string): Promise<any> {\n if (filename.startsWith('http')) {\n const response = await fetch(filename);\n const code = await response.text();\n return requireFromString(code);\n }\n\n if (!filename.startsWith('/')) {\n filename = `${process.cwd()}/${filename}`;\n }\n const code = await fs.readFileSync(filename, 'utf8');\n return requireFromString(code);\n}\n\n// Dynamically require from string\n// - `code` - Required - Type: string - Module code.\n// - `filename` - Type: string - Default: '' - Optional filename.\n// - `options.appendPaths` Type: Array List of paths, that will be appended to module paths.\n// Useful, when you want to be able require modules from these paths.\n// - `options.prependPaths` Type: Array Same as appendPaths, but paths will be prepended.\nexport function requireFromString(\n code: string,\n filename = '',\n options?: {\n prependPaths?: string[];\n appendPaths?: string[];\n }\n): any {\n if (typeof filename === 'object') {\n options = filename;\n filename = '';\n }\n\n if (typeof code !== 'string') {\n throw new Error(`code must be a string, not ${typeof code}`);\n }\n\n // @ts-ignore\n const paths = Module._nodeModulePaths(path.dirname(filename));\n\n const parent = typeof module !== 'undefined' && module?.parent;\n\n // @ts-ignore\n const newModule = new Module(filename, parent);\n newModule.filename = filename;\n newModule.paths = ([] as string[])\n .concat(options?.prependPaths || [])\n .concat(paths)\n .concat(options?.appendPaths || []);\n // @ts-ignore\n newModule._compile(code, filename);\n\n if (parent && parent.children) {\n parent.children.splice(parent.children.indexOf(newModule), 1);\n }\n\n return newModule.exports;\n}\n"],"mappings":"AAMA,OAAOA,MAAM,MAAM,QAAQ;AAC3B,OAAO,KAAKC,IAAI,MAAM,MAAM;AAC5B,OAAO,KAAKC,EAAE,MAAM,IAAI;AAOxB,OAAO,eAAeC,qBAAqBA,CAACC,QAAgB,EAAwB;EAClF,IAAIA,QAAQ,CAACC,UAAU,CAAC,MAAM,CAAC,EAAE;IAC/B,MAAMC,QAAQ,GAAG,MAAMC,KAAK,CAACH,QAAQ,CAAC;IACtC,OAAO,MAAME,QAAQ,CAACE,WAAW,CAAC,CAAC;EACrC;EACA,MAAMC,MAAM,GAAGP,EAAE,CAACQ,YAAY,CAACN,QAAQ,CAAC;EACxC,OAAOK,MAAM,CAACA,MAAM;AACtB;AAOA,OAAO,eAAeE,cAAcA,CAACP,QAAgB,EAAmB;EACtE,IAAIA,QAAQ,CAACC,UAAU,CAAC,MAAM,CAAC,EAAE;IAC/B,MAAMC,QAAQ,GAAG,MAAMC,KAAK,CAACH,QAAQ,CAAC;IACtC,OAAO,MAAME,QAAQ,CAACM,IAAI,CAAC,CAAC;EAC9B;EACA,MAAMA,IAAI,GAAGV,EAAE,CAACQ,YAAY,CAACN,QAAQ,EAAE,MAAM,CAAC;EAC9C,OAAOQ,IAAI;AACb;AAMA,OAAO,eAAeC,eAAeA,CAACT,QAAgB,EAAgB;EACpE,IAAIA,QAAQ,CAACC,UAAU,CAAC,MAAM,CAAC,EAAE;IAC/B,MAAMC,QAAQ,GAAG,MAAMC,KAAK,CAACH,QAAQ,CAAC;IACtC,MAAMU,IAAI,GAAG,MAAMR,QAAQ,CAACM,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,EAAAb,QAAA,GAAAK,OAAO,cAAAL,QAAA,uBAAPA,QAAA,CAASc,YAAY,KAAI,EAAE,CAAC,CACnCD,MAAM,CAACN,KAAK,CAAC,CACbM,MAAM,CAAC,EAAAZ,SAAA,GAAAI,OAAO,cAAAJ,SAAA,uBAAPA,SAAA,CAASc,WAAW,KAAI,EAAE,CAAC;EAErCH,SAAS,CAACI,QAAQ,CAACrB,IAAI,EAAEV,QAAQ,CAAC;EAElC,IAAIyB,MAAM,IAAIA,MAAM,CAACO,QAAQ,EAAE;IAC7BP,MAAM,CAACO,QAAQ,CAACC,MAAM,CAACR,MAAM,CAACO,QAAQ,CAACE,OAAO,CAACP,SAAS,CAAC,EAAE,CAAC,CAAC;EAC/D;EAEA,OAAOA,SAAS,CAACQ,OAAO;AAC1B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/worker-utils",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.6",
|
|
4
4
|
"description": "Utilities for running tasks on worker threads",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -38,13 +38,10 @@
|
|
|
38
38
|
"path": false,
|
|
39
39
|
"fs": false,
|
|
40
40
|
"./src/lib/node/worker_threads.ts": "./src/lib/node/worker_threads-browser.ts",
|
|
41
|
-
"./dist/
|
|
42
|
-
"./dist/esm/lib/node/worker_threads.js": "./dist/esm/lib/node/worker_threads-browser.js",
|
|
41
|
+
"./dist/lib/node/worker_threads.js": "./dist/lib/node/worker_threads-browser.js",
|
|
43
42
|
"./src/lib/node/require-utils.node.ts": false,
|
|
44
|
-
"./dist/
|
|
45
|
-
"./dist/esm/lib/node/require-utils.node.js": false,
|
|
43
|
+
"./dist/lib/node/require-utils.node.js": false,
|
|
46
44
|
"./src/lib/process-utils/child-process-proxy.ts": false,
|
|
47
|
-
"./dist/es5/lib/process-utils/child-process-proxy.js": false,
|
|
48
45
|
"./dist/esm/lib/process-utils/child-process-proxy.js": false
|
|
49
46
|
},
|
|
50
47
|
"scripts": {
|
|
@@ -55,5 +52,5 @@
|
|
|
55
52
|
"dependencies": {
|
|
56
53
|
"@babel/runtime": "^7.3.1"
|
|
57
54
|
},
|
|
58
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "2840f605b7a551e2ffef5f960231d989a0414c50"
|
|
59
56
|
}
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// this file is not visible to webpack (it is excluded in the package.json "browser" field).
|
|
6
6
|
|
|
7
7
|
import Module from 'module';
|
|
8
|
-
import path from 'path';
|
|
9
|
-
import fs from 'fs';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
import * as fs from 'fs';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Load a file from local file system
|