@lwrjs/esbuild 0.11.0-alpha.11
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 +81 -0
- package/build/es/index.d.ts +7 -0
- package/build/es/index.js +70 -0
- package/package.json +55 -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,81 @@
|
|
|
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_esbuild = __toModule(require("esbuild"));
|
|
32
|
+
var esbuild = import_esbuild.default;
|
|
33
|
+
if (!import_esbuild.default) {
|
|
34
|
+
try {
|
|
35
|
+
esbuild = require("esbuild");
|
|
36
|
+
} catch {
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
var isCommonJs = typeof module !== "undefined";
|
|
40
|
+
var ESBUILD_EXTENSION_PLUGIN = function(absFilePath, format) {
|
|
41
|
+
return {
|
|
42
|
+
name: "replace-extension-plugin",
|
|
43
|
+
setup(build) {
|
|
44
|
+
build.onResolve({filter: /.*/}, ({path, importer, resolveDir}) => {
|
|
45
|
+
if (path !== absFilePath) {
|
|
46
|
+
if (path.startsWith(".")) {
|
|
47
|
+
const importeeExt = (0, import_path.extname)(path);
|
|
48
|
+
const ext = importeeExt !== "" ? importeeExt : ".ts";
|
|
49
|
+
let absPath = (0, import_path.join)((0, import_path.dirname)(importer), `${path}${ext}`);
|
|
50
|
+
if (!import_fs.default.existsSync(absPath) && ext === ".js") {
|
|
51
|
+
absPath = absPath.replace(".js", ".ts");
|
|
52
|
+
}
|
|
53
|
+
return {path: absPath};
|
|
54
|
+
} else {
|
|
55
|
+
return {
|
|
56
|
+
external: true
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
async function transpileTs(tsAbsPath, {rootDir, cacheDir}) {
|
|
65
|
+
const format = isCommonJs ? "cjs" : "esm";
|
|
66
|
+
const ext = format === "esm" ? ".mjs" : ".cjs";
|
|
67
|
+
const pathRelativeToRoot = tsAbsPath.replace(new RegExp(`^${rootDir}`), "");
|
|
68
|
+
const outBasename = pathRelativeToRoot.replace(/\//g, "_");
|
|
69
|
+
const outFilename = outBasename.replace(/\.ts$/, ext);
|
|
70
|
+
const outfile = (0, import_path.join)(cacheDir, outFilename);
|
|
71
|
+
await esbuild.build({
|
|
72
|
+
format,
|
|
73
|
+
bundle: true,
|
|
74
|
+
logLevel: "error",
|
|
75
|
+
entryPoints: [tsAbsPath],
|
|
76
|
+
sourcemap: true,
|
|
77
|
+
outfile,
|
|
78
|
+
plugins: [ESBUILD_EXTENSION_PLUGIN(tsAbsPath, format)]
|
|
79
|
+
});
|
|
80
|
+
return outfile;
|
|
81
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { join, dirname, extname } from 'path';
|
|
3
|
+
import esbuildEsm from 'esbuild';
|
|
4
|
+
// https://github.com/evanw/esbuild/issues/706
|
|
5
|
+
// Fixed in 0.11.0 but upgrading past 0.9.7 has caused breaking changes for consumers...
|
|
6
|
+
// https://github.com/salesforce-experience-platform-emu/lwr/issues/1014
|
|
7
|
+
let esbuild = esbuildEsm;
|
|
8
|
+
if (!esbuildEsm) {
|
|
9
|
+
try {
|
|
10
|
+
esbuild = require('esbuild');
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
/* this is to support mjs/cjs dual impl */
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// This is important as it checks which compilation to use esm or cjs based on the current way NodeJS is configured
|
|
17
|
+
const isCommonJs = typeof module !== 'undefined';
|
|
18
|
+
/* istanbul ignore next */
|
|
19
|
+
const ESBUILD_EXTENSION_PLUGIN = function (absFilePath, format) {
|
|
20
|
+
return {
|
|
21
|
+
name: 'replace-extension-plugin',
|
|
22
|
+
setup(build) {
|
|
23
|
+
build.onResolve({ filter: /.*/ }, ({ path, importer, resolveDir }) => {
|
|
24
|
+
if (path !== absFilePath) {
|
|
25
|
+
if (path.startsWith('.')) {
|
|
26
|
+
const importeeExt = extname(path);
|
|
27
|
+
const ext = importeeExt !== '' ? importeeExt : '.ts';
|
|
28
|
+
let absPath = join(dirname(importer), `${path}${ext}`);
|
|
29
|
+
// If typescript import is a ".js" try to find the equivalent .ts
|
|
30
|
+
// We do this to keep consistency with TS resolution
|
|
31
|
+
if (!fs.existsSync(absPath) && ext === '.js') {
|
|
32
|
+
absPath = absPath.replace('.js', '.ts');
|
|
33
|
+
}
|
|
34
|
+
return { path: absPath };
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return {
|
|
38
|
+
external: true,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
// Transpile a typescript file and cache it
|
|
47
|
+
// The filename of the cached file is:
|
|
48
|
+
// - the path to the ts file relative to the project root
|
|
49
|
+
// - with all slashes replaced by underscores
|
|
50
|
+
// - and a new file extension of .mjs or .cjs
|
|
51
|
+
// eg: "/rootDir/path/to/file.ts" => "/cacheDir/path_to_file.*js"
|
|
52
|
+
export async function transpileTs(tsAbsPath, { rootDir, cacheDir }) {
|
|
53
|
+
const format = isCommonJs ? 'cjs' : 'esm';
|
|
54
|
+
const ext = format === 'esm' ? '.mjs' : '.cjs';
|
|
55
|
+
const pathRelativeToRoot = tsAbsPath.replace(new RegExp(`^${rootDir}`), '');
|
|
56
|
+
const outBasename = pathRelativeToRoot.replace(/\//g, '_'); // replace "/" with "_" in path
|
|
57
|
+
const outFilename = outBasename.replace(/\.ts$/, ext);
|
|
58
|
+
const outfile = join(cacheDir, outFilename);
|
|
59
|
+
await esbuild.build({
|
|
60
|
+
format,
|
|
61
|
+
bundle: true,
|
|
62
|
+
logLevel: 'error',
|
|
63
|
+
entryPoints: [tsAbsPath],
|
|
64
|
+
sourcemap: true,
|
|
65
|
+
outfile,
|
|
66
|
+
plugins: [ESBUILD_EXTENSION_PLUGIN(tsAbsPath, format)],
|
|
67
|
+
});
|
|
68
|
+
return outfile;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lwrjs/esbuild",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"version": "0.11.0-alpha.11",
|
|
8
|
+
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/salesforce-experience-platform-emu/lwr.git",
|
|
12
|
+
"directory": "packages/@lwrjs/esbuild"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/salesforce-experience-platform-emu/lwr/issues"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"types": "build/es/index.d.ts",
|
|
19
|
+
"main": "build/cjs/index.cjs",
|
|
20
|
+
"module": "build/es/index.js",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": "./build/es/index.js",
|
|
24
|
+
"require": "./build/cjs/index.cjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"build/**/*.js",
|
|
29
|
+
"build/**/*.cjs",
|
|
30
|
+
"build/**/*.d.ts"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc -b",
|
|
34
|
+
"clean": "rm -rf build node_modules",
|
|
35
|
+
"test": "jest"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@lwrjs/types": "0.11.0-alpha.11",
|
|
39
|
+
"jest": "^26.6.3",
|
|
40
|
+
"ts-jest": "^26.5.6",
|
|
41
|
+
"typescript": "^4.9.5"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@lwrjs/diagnostics": "0.11.0-alpha.11",
|
|
45
|
+
"@lwrjs/shared-utils": "0.11.0-alpha.11",
|
|
46
|
+
"esbuild": "^0.9.7"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=16.0.0"
|
|
50
|
+
},
|
|
51
|
+
"volta": {
|
|
52
|
+
"extends": "../../../package.json"
|
|
53
|
+
},
|
|
54
|
+
"gitHead": "acb9df6ee7887b683e28ad43e00df311256d6018"
|
|
55
|
+
}
|