@ohos-ports/lwrjs-esbuild 0.24.0-beta.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/LICENSE +10 -0
- package/build/cjs/index.cjs +82 -0
- package/build/es/index.d.ts +7 -0
- package/build/es/index.js +71 -0
- package/esbuild-ohos/LICENSE.md +21 -0
- package/esbuild-ohos/README.md +3 -0
- package/esbuild-ohos/bin/esbuild +223 -0
- package/esbuild-ohos/install.js +300 -0
- package/esbuild-ohos/lib/main.d.ts +716 -0
- package/esbuild-ohos/lib/main.js +2540 -0
- package/esbuild-ohos/package.json +74 -0
- package/esbuild-openharmony-arm64/bin/esbuild +0 -0
- package/esbuild-openharmony-arm64/package.json +14 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
MIT LICENSE
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020, Salesforce.com, Inc.
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
7
|
+
|
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
11
|
+
};
|
|
12
|
+
var __exportStar = (target, module2, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toModule = (module2) => {
|
|
21
|
+
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// packages/@lwrjs/esbuild/src/index.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
transpileTs: () => transpileTs
|
|
28
|
+
});
|
|
29
|
+
var import_fs = __toModule(require("fs"));
|
|
30
|
+
var import_path = __toModule(require("path"));
|
|
31
|
+
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
32
|
+
var import_esbuild = __toModule(require("esbuild"));
|
|
33
|
+
var esbuild = import_esbuild.default;
|
|
34
|
+
if (!import_esbuild.default) {
|
|
35
|
+
try {
|
|
36
|
+
esbuild = require("esbuild");
|
|
37
|
+
} catch {
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
var isCommonJs = typeof module !== "undefined";
|
|
41
|
+
var ESBUILD_EXTENSION_PLUGIN = function(absFilePath, format) {
|
|
42
|
+
return {
|
|
43
|
+
name: "replace-extension-plugin",
|
|
44
|
+
setup(build) {
|
|
45
|
+
build.onResolve({filter: /.*/}, ({path, importer, resolveDir}) => {
|
|
46
|
+
if (path !== absFilePath) {
|
|
47
|
+
if (path.startsWith(".")) {
|
|
48
|
+
const importeeExt = (0, import_path.extname)(path);
|
|
49
|
+
const ext = importeeExt !== "" ? importeeExt : ".ts";
|
|
50
|
+
let absPath = (0, import_path.join)((0, import_path.dirname)(importer), `${path}${ext}`);
|
|
51
|
+
if (!import_fs.default.existsSync(absPath) && ext === ".js") {
|
|
52
|
+
absPath = absPath.replace(".js", ".ts");
|
|
53
|
+
}
|
|
54
|
+
return {path: absPath};
|
|
55
|
+
} else {
|
|
56
|
+
return {
|
|
57
|
+
external: true
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
async function transpileTs(tsAbsPath, {rootDir, cacheDir}) {
|
|
66
|
+
const format = isCommonJs ? "cjs" : "esm";
|
|
67
|
+
const ext = format === "esm" ? ".mjs" : ".cjs";
|
|
68
|
+
const pathRelativeToRoot = (0, import_path.relative)(rootDir, tsAbsPath);
|
|
69
|
+
const outBasename = pathRelativeToRoot.replace(new RegExp(`\\${import_path.sep}`, "g"), "_");
|
|
70
|
+
const outFilename = outBasename.replace(/\.ts$/, ext);
|
|
71
|
+
const outfile = (0, import_shared_utils.toForwardSlash)((0, import_path.join)(cacheDir, outFilename));
|
|
72
|
+
await esbuild.build({
|
|
73
|
+
format,
|
|
74
|
+
bundle: true,
|
|
75
|
+
logLevel: "error",
|
|
76
|
+
entryPoints: [tsAbsPath],
|
|
77
|
+
sourcemap: true,
|
|
78
|
+
outfile,
|
|
79
|
+
plugins: [ESBUILD_EXTENSION_PLUGIN(tsAbsPath, format)]
|
|
80
|
+
});
|
|
81
|
+
return outfile;
|
|
82
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { join, dirname, extname, relative, sep } from 'path';
|
|
3
|
+
import { toForwardSlash } from '@lwrjs/shared-utils';
|
|
4
|
+
import esbuildEsm from 'esbuild';
|
|
5
|
+
// https://github.com/evanw/esbuild/issues/706
|
|
6
|
+
// Fixed in 0.11.0 but upgrading past 0.9.7 has caused breaking changes for consumers...
|
|
7
|
+
// https://github.com/salesforce-experience-platform-emu/lwr/issues/1014
|
|
8
|
+
let esbuild = esbuildEsm;
|
|
9
|
+
if (!esbuildEsm) {
|
|
10
|
+
try {
|
|
11
|
+
esbuild = require('esbuild');
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
/* this is to support mjs/cjs dual impl */
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
// This is important as it checks which compilation to use esm or cjs based on the current way NodeJS is configured
|
|
18
|
+
const isCommonJs = typeof module !== 'undefined';
|
|
19
|
+
/* istanbul ignore next */
|
|
20
|
+
const ESBUILD_EXTENSION_PLUGIN = function (absFilePath, format) {
|
|
21
|
+
return {
|
|
22
|
+
name: 'replace-extension-plugin',
|
|
23
|
+
setup(build) {
|
|
24
|
+
build.onResolve({ filter: /.*/ }, ({ path, importer, resolveDir }) => {
|
|
25
|
+
if (path !== absFilePath) {
|
|
26
|
+
if (path.startsWith('.')) {
|
|
27
|
+
const importeeExt = extname(path);
|
|
28
|
+
const ext = importeeExt !== '' ? importeeExt : '.ts';
|
|
29
|
+
let absPath = join(dirname(importer), `${path}${ext}`);
|
|
30
|
+
// If typescript import is a ".js" try to find the equivalent .ts
|
|
31
|
+
// We do this to keep consistency with TS resolution
|
|
32
|
+
if (!fs.existsSync(absPath) && ext === '.js') {
|
|
33
|
+
absPath = absPath.replace('.js', '.ts');
|
|
34
|
+
}
|
|
35
|
+
return { path: absPath };
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return {
|
|
39
|
+
external: true,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
// Transpile a typescript file and cache it
|
|
48
|
+
// The filename of the cached file is:
|
|
49
|
+
// - the path to the ts file relative to the project root
|
|
50
|
+
// - with all slashes replaced by underscores
|
|
51
|
+
// - and a new file extension of .mjs or .cjs
|
|
52
|
+
// eg: "/rootDir/path/to/file.ts" => "/cacheDir/path_to_file.*js"
|
|
53
|
+
export async function transpileTs(tsAbsPath, { rootDir, cacheDir }) {
|
|
54
|
+
const format = isCommonJs ? 'cjs' : 'esm';
|
|
55
|
+
const ext = format === 'esm' ? '.mjs' : '.cjs';
|
|
56
|
+
const pathRelativeToRoot = relative(rootDir, tsAbsPath);
|
|
57
|
+
const outBasename = pathRelativeToRoot.replace(new RegExp(`\\${sep}`, 'g'), '_'); // replace "/" with "_" in path
|
|
58
|
+
const outFilename = outBasename.replace(/\.ts$/, ext);
|
|
59
|
+
const outfile = toForwardSlash(join(cacheDir, outFilename));
|
|
60
|
+
await esbuild.build({
|
|
61
|
+
format,
|
|
62
|
+
bundle: true,
|
|
63
|
+
logLevel: 'error',
|
|
64
|
+
entryPoints: [tsAbsPath],
|
|
65
|
+
sourcemap: true,
|
|
66
|
+
outfile,
|
|
67
|
+
plugins: [ESBUILD_EXTENSION_PLUGIN(tsAbsPath, format)],
|
|
68
|
+
});
|
|
69
|
+
return outfile;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Evan Wallace
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// lib/npm/node-platform.ts
|
|
27
|
+
var fs = require("fs");
|
|
28
|
+
var os = require("os");
|
|
29
|
+
var path = require("path");
|
|
30
|
+
var ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH;
|
|
31
|
+
var isValidBinaryPath = (x) => !!x && x !== "/usr/bin/esbuild";
|
|
32
|
+
var packageDarwin_arm64 = "@esbuild/darwin-arm64";
|
|
33
|
+
var packageDarwin_x64 = "@esbuild/darwin-x64";
|
|
34
|
+
var knownWindowsPackages = {
|
|
35
|
+
"win32 arm64 LE": "@esbuild/win32-arm64",
|
|
36
|
+
"win32 ia32 LE": "@esbuild/win32-ia32",
|
|
37
|
+
"win32 x64 LE": "@esbuild/win32-x64"
|
|
38
|
+
};
|
|
39
|
+
var knownUnixlikePackages = {
|
|
40
|
+
"aix ppc64 BE": "@esbuild/aix-ppc64",
|
|
41
|
+
"android arm64 LE": "@esbuild/android-arm64",
|
|
42
|
+
"darwin arm64 LE": "@esbuild/darwin-arm64",
|
|
43
|
+
"darwin x64 LE": "@esbuild/darwin-x64",
|
|
44
|
+
"freebsd arm64 LE": "@esbuild/freebsd-arm64",
|
|
45
|
+
"freebsd x64 LE": "@esbuild/freebsd-x64",
|
|
46
|
+
"linux arm LE": "@esbuild/linux-arm",
|
|
47
|
+
"linux arm64 LE": "@esbuild/linux-arm64",
|
|
48
|
+
"linux ia32 LE": "@esbuild/linux-ia32",
|
|
49
|
+
"linux mips64el LE": "@esbuild/linux-mips64el",
|
|
50
|
+
"linux ppc64 LE": "@esbuild/linux-ppc64",
|
|
51
|
+
"linux riscv64 LE": "@esbuild/linux-riscv64",
|
|
52
|
+
"linux s390x BE": "@esbuild/linux-s390x",
|
|
53
|
+
"linux x64 LE": "@esbuild/linux-x64",
|
|
54
|
+
"linux loong64 LE": "@esbuild/linux-loong64",
|
|
55
|
+
"netbsd arm64 LE": "@esbuild/netbsd-arm64",
|
|
56
|
+
"netbsd x64 LE": "@esbuild/netbsd-x64",
|
|
57
|
+
"openbsd arm64 LE": "@esbuild/openbsd-arm64",
|
|
58
|
+
"openbsd x64 LE": "@esbuild/openbsd-x64",
|
|
59
|
+
"openharmony arm64 LE": "@esbuild/openharmony-arm64",
|
|
60
|
+
"sunos x64 LE": "@esbuild/sunos-x64"
|
|
61
|
+
};
|
|
62
|
+
var knownWebAssemblyFallbackPackages = {
|
|
63
|
+
"android arm LE": "@esbuild/android-arm",
|
|
64
|
+
"android x64 LE": "@esbuild/android-x64"
|
|
65
|
+
};
|
|
66
|
+
function pkgAndSubpathForCurrentPlatform() {
|
|
67
|
+
let pkg;
|
|
68
|
+
let subpath;
|
|
69
|
+
let isWASM2 = false;
|
|
70
|
+
let platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
|
|
71
|
+
if (platformKey in knownWindowsPackages) {
|
|
72
|
+
pkg = knownWindowsPackages[platformKey];
|
|
73
|
+
subpath = "esbuild.exe";
|
|
74
|
+
} else if (platformKey in knownUnixlikePackages) {
|
|
75
|
+
pkg = knownUnixlikePackages[platformKey];
|
|
76
|
+
subpath = "bin/esbuild";
|
|
77
|
+
} else if (platformKey in knownWebAssemblyFallbackPackages) {
|
|
78
|
+
pkg = knownWebAssemblyFallbackPackages[platformKey];
|
|
79
|
+
subpath = "bin/esbuild";
|
|
80
|
+
isWASM2 = true;
|
|
81
|
+
} else {
|
|
82
|
+
throw new Error(`Unsupported platform: ${platformKey}`);
|
|
83
|
+
}
|
|
84
|
+
return { pkg, subpath, isWASM: isWASM2 };
|
|
85
|
+
}
|
|
86
|
+
function pkgForSomeOtherPlatform() {
|
|
87
|
+
const libMainJS = require.resolve("esbuild");
|
|
88
|
+
const nodeModulesDirectory = path.dirname(path.dirname(path.dirname(libMainJS)));
|
|
89
|
+
if (path.basename(nodeModulesDirectory) === "node_modules") {
|
|
90
|
+
for (const unixKey in knownUnixlikePackages) {
|
|
91
|
+
try {
|
|
92
|
+
const pkg = knownUnixlikePackages[unixKey];
|
|
93
|
+
if (fs.existsSync(path.join(nodeModulesDirectory, pkg))) return pkg;
|
|
94
|
+
} catch {
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const windowsKey in knownWindowsPackages) {
|
|
98
|
+
try {
|
|
99
|
+
const pkg = knownWindowsPackages[windowsKey];
|
|
100
|
+
if (fs.existsSync(path.join(nodeModulesDirectory, pkg))) return pkg;
|
|
101
|
+
} catch {
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
function downloadedBinPath(pkg, subpath) {
|
|
108
|
+
const esbuildLibDir = path.dirname(require.resolve("esbuild"));
|
|
109
|
+
return path.join(esbuildLibDir, `downloaded-${pkg.replace("/", "-")}-${path.basename(subpath)}`);
|
|
110
|
+
}
|
|
111
|
+
function generateBinPath() {
|
|
112
|
+
if (isValidBinaryPath(ESBUILD_BINARY_PATH)) {
|
|
113
|
+
if (!fs.existsSync(ESBUILD_BINARY_PATH)) {
|
|
114
|
+
console.warn(`[esbuild] Ignoring bad configuration: ESBUILD_BINARY_PATH=${ESBUILD_BINARY_PATH}`);
|
|
115
|
+
} else {
|
|
116
|
+
return { binPath: ESBUILD_BINARY_PATH, isWASM: false };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const { pkg, subpath, isWASM: isWASM2 } = pkgAndSubpathForCurrentPlatform();
|
|
120
|
+
let binPath2;
|
|
121
|
+
try {
|
|
122
|
+
binPath2 = require.resolve(`${pkg}/${subpath}`);
|
|
123
|
+
} catch (e) {
|
|
124
|
+
binPath2 = downloadedBinPath(pkg, subpath);
|
|
125
|
+
if (!fs.existsSync(binPath2)) {
|
|
126
|
+
try {
|
|
127
|
+
require.resolve(pkg);
|
|
128
|
+
} catch {
|
|
129
|
+
const otherPkg = pkgForSomeOtherPlatform();
|
|
130
|
+
if (otherPkg) {
|
|
131
|
+
let suggestions = `
|
|
132
|
+
Specifically the "${otherPkg}" package is present but this platform
|
|
133
|
+
needs the "${pkg}" package instead. People often get into this
|
|
134
|
+
situation by installing esbuild on Windows or macOS and copying "node_modules"
|
|
135
|
+
into a Docker image that runs Linux, or by copying "node_modules" between
|
|
136
|
+
Windows and WSL environments.
|
|
137
|
+
|
|
138
|
+
If you are installing with npm, you can try not copying the "node_modules"
|
|
139
|
+
directory when you copy the files over, and running "npm ci" or "npm install"
|
|
140
|
+
on the destination platform after the copy. Or you could consider using yarn
|
|
141
|
+
instead of npm which has built-in support for installing a package on multiple
|
|
142
|
+
platforms simultaneously.
|
|
143
|
+
|
|
144
|
+
If you are installing with yarn, you can try listing both this platform and the
|
|
145
|
+
other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
|
|
146
|
+
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
|
147
|
+
Keep in mind that this means multiple copies of esbuild will be present.
|
|
148
|
+
`;
|
|
149
|
+
if (pkg === packageDarwin_x64 && otherPkg === packageDarwin_arm64 || pkg === packageDarwin_arm64 && otherPkg === packageDarwin_x64) {
|
|
150
|
+
suggestions = `
|
|
151
|
+
Specifically the "${otherPkg}" package is present but this platform
|
|
152
|
+
needs the "${pkg}" package instead. People often get into this
|
|
153
|
+
situation by installing esbuild with npm running inside of Rosetta 2 and then
|
|
154
|
+
trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta
|
|
155
|
+
2 is Apple's on-the-fly x86_64-to-arm64 translation service).
|
|
156
|
+
|
|
157
|
+
If you are installing with npm, you can try ensuring that both npm and node are
|
|
158
|
+
not running under Rosetta 2 and then reinstalling esbuild. This likely involves
|
|
159
|
+
changing how you installed npm and/or node. For example, installing node with
|
|
160
|
+
the universal installer here should work: https://nodejs.org/en/download/. Or
|
|
161
|
+
you could consider using yarn instead of npm which has built-in support for
|
|
162
|
+
installing a package on multiple platforms simultaneously.
|
|
163
|
+
|
|
164
|
+
If you are installing with yarn, you can try listing both "arm64" and "x64"
|
|
165
|
+
in your ".yarnrc.yml" file using the "supportedArchitectures" feature:
|
|
166
|
+
https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
|
167
|
+
Keep in mind that this means multiple copies of esbuild will be present.
|
|
168
|
+
`;
|
|
169
|
+
}
|
|
170
|
+
throw new Error(`
|
|
171
|
+
You installed esbuild for another platform than the one you're currently using.
|
|
172
|
+
This won't work because esbuild is written with native code and needs to
|
|
173
|
+
install a platform-specific binary executable.
|
|
174
|
+
${suggestions}
|
|
175
|
+
Another alternative is to use the "esbuild-wasm" package instead, which works
|
|
176
|
+
the same way on all platforms. But it comes with a heavy performance cost and
|
|
177
|
+
can sometimes be 10x slower than the "esbuild" package, so you may also not
|
|
178
|
+
want to do that.
|
|
179
|
+
`);
|
|
180
|
+
}
|
|
181
|
+
throw new Error(`The package "${pkg}" could not be found, and is needed by esbuild.
|
|
182
|
+
|
|
183
|
+
If you are installing esbuild with npm, make sure that you don't specify the
|
|
184
|
+
"--no-optional" or "--omit=optional" flags. The "optionalDependencies" feature
|
|
185
|
+
of "package.json" is used by esbuild to install the correct binary executable
|
|
186
|
+
for your current platform.`);
|
|
187
|
+
}
|
|
188
|
+
throw e;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (/\.zip\//.test(binPath2)) {
|
|
192
|
+
let pnpapi;
|
|
193
|
+
try {
|
|
194
|
+
pnpapi = require("pnpapi");
|
|
195
|
+
} catch (e) {
|
|
196
|
+
}
|
|
197
|
+
if (pnpapi) {
|
|
198
|
+
const root = pnpapi.getPackageInformation(pnpapi.topLevel).packageLocation;
|
|
199
|
+
const binTargetPath = path.join(
|
|
200
|
+
root,
|
|
201
|
+
"node_modules",
|
|
202
|
+
".cache",
|
|
203
|
+
"esbuild",
|
|
204
|
+
`pnpapi-${pkg.replace("/", "-")}-${"0.28.1"}-${path.basename(subpath)}`
|
|
205
|
+
);
|
|
206
|
+
if (!fs.existsSync(binTargetPath)) {
|
|
207
|
+
fs.mkdirSync(path.dirname(binTargetPath), { recursive: true });
|
|
208
|
+
fs.copyFileSync(binPath2, binTargetPath);
|
|
209
|
+
fs.chmodSync(binTargetPath, 493);
|
|
210
|
+
}
|
|
211
|
+
return { binPath: binTargetPath, isWASM: isWASM2 };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return { binPath: binPath2, isWASM: isWASM2 };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// lib/npm/node-shim.ts
|
|
218
|
+
var { binPath, isWASM } = generateBinPath();
|
|
219
|
+
if (isWASM) {
|
|
220
|
+
require("child_process").execFileSync("node", [binPath].concat(process.argv.slice(2)), { stdio: "inherit" });
|
|
221
|
+
} else {
|
|
222
|
+
require("child_process").execFileSync(binPath, process.argv.slice(2), { stdio: "inherit" });
|
|
223
|
+
}
|