@ohos-ports/swc-core 1.3.14-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/CHANGELOG.md +11281 -0
- package/LICENSE +201 -0
- package/README.md +93 -0
- package/Visitor.d.ts +214 -0
- package/Visitor.js +1395 -0
- package/binding.d.ts +16 -0
- package/binding.js +283 -0
- package/index.d.ts +107 -0
- package/index.js +426 -0
- package/package.json +90 -0
- package/postinstall.js +147 -0
- package/run_swcx.js +85 -0
- package/spack.d.ts +50 -0
- package/spack.js +83 -0
- package/swc.openharmony-arm64.node +4 -0
- package/types.d.ts +1865 -0
- package/types.js +2 -0
- package/util.d.ts +1 -0
- package/util.js +104 -0
package/run_swcx.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
/**
|
|
17
|
+
* Lightweight entrypoint to native swc cli binary.
|
|
18
|
+
*
|
|
19
|
+
* This is to locate corresponding per-platform executables correctly, as well as
|
|
20
|
+
* let npm links binary to `node_modules/.bin` allows npm-related ecosystem (`npx swcx`, etcs)
|
|
21
|
+
* works correctly. However, it means spawning native binary still requires warmup from node.js
|
|
22
|
+
* process.
|
|
23
|
+
*
|
|
24
|
+
* NOTE: THIS IS NOT A PERMANENT APPROACH.
|
|
25
|
+
* Distribution of native cli binary is not fully concluded yet. This allows easier
|
|
26
|
+
* opt-in while implementation is in progress to collect feedback.
|
|
27
|
+
*/
|
|
28
|
+
const child_process_1 = require("child_process");
|
|
29
|
+
const path_1 = __importDefault(require("path"));
|
|
30
|
+
const fs_1 = require("fs");
|
|
31
|
+
const { platform, arch } = process;
|
|
32
|
+
const isMusl = () => (() => {
|
|
33
|
+
function isMusl() {
|
|
34
|
+
if (!process.report || typeof process.report.getReport !== "function") {
|
|
35
|
+
try {
|
|
36
|
+
return (0, fs_1.readFileSync)("/usr/bin/ldd", "utf8").includes("musl");
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const { glibcVersionRuntime } = process.report.getReport().header;
|
|
44
|
+
return !glibcVersionRuntime;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return isMusl();
|
|
48
|
+
})();
|
|
49
|
+
const platformPackagesMap = {
|
|
50
|
+
"android": {
|
|
51
|
+
"arm64": "@swc/core-android-arm64",
|
|
52
|
+
"arm": "@swc/core-android-arm-eabi",
|
|
53
|
+
},
|
|
54
|
+
"win32": {
|
|
55
|
+
"x64": "@swc/core-win32-x64-msvc",
|
|
56
|
+
"ia32": "@swc/core-win32-ia32-msvc",
|
|
57
|
+
"arm64": "@swc/core-win32-arm64-msvc"
|
|
58
|
+
},
|
|
59
|
+
"darwin": {
|
|
60
|
+
"x64": "@swc/core-darwin-x64",
|
|
61
|
+
"arm64": "@swc/core-darwin-arm64",
|
|
62
|
+
},
|
|
63
|
+
"freebsd": {
|
|
64
|
+
"x64": "@swc/core-freebsd-x64",
|
|
65
|
+
},
|
|
66
|
+
"linux": {
|
|
67
|
+
"x64": `@swc/core-linux-x64-${isMusl() ? 'musl' : 'gnu'}`,
|
|
68
|
+
"arm64": `@swc/core-linux-arm64-${isMusl() ? 'musl' : 'gnu'}`,
|
|
69
|
+
"arm": "@swc/core-linux-arm64-gnu"
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
const inferBinaryName = () => {
|
|
73
|
+
const packageName = platformPackagesMap[platform][arch];
|
|
74
|
+
if (!packageName) {
|
|
75
|
+
throw new Error(`Unsupported platform: binary for '${platform} ${arch}' is not available`);
|
|
76
|
+
}
|
|
77
|
+
return path_1.default.join(path_1.default.dirname(require.resolve(packageName)), platform === 'win32' ? 'swc.exe' : 'swc');
|
|
78
|
+
};
|
|
79
|
+
const executeBinary = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
const binary = inferBinaryName();
|
|
81
|
+
const [, , ...args] = process.argv;
|
|
82
|
+
const options = { cwd: process.cwd(), stdio: "inherit" };
|
|
83
|
+
return (0, child_process_1.spawn)(binary, args, options);
|
|
84
|
+
});
|
|
85
|
+
executeBinary().catch((e) => console.error(e));
|
package/spack.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Options } from "./types";
|
|
2
|
+
export declare type BundleInput = BundleOptions | BundleOptions[];
|
|
3
|
+
export declare function compileBundleOptions(config: BundleInput | string | undefined): Promise<BundleInput>;
|
|
4
|
+
/**
|
|
5
|
+
* Usage: In `spack.config.js` / `spack.config.ts`, you can utilize type annotations (to get autocompletions) like
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { config } from '@swc/core/spack';
|
|
9
|
+
*
|
|
10
|
+
* export default config({
|
|
11
|
+
* name: 'web',
|
|
12
|
+
* });
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
*
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
export declare function config(c: BundleInput): BundleInput;
|
|
19
|
+
export interface BundleOptions extends SpackConfig {
|
|
20
|
+
workingDir?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* `spack.config,js`
|
|
24
|
+
*/
|
|
25
|
+
export interface SpackConfig {
|
|
26
|
+
/**
|
|
27
|
+
* @default process.env.NODE_ENV
|
|
28
|
+
*/
|
|
29
|
+
mode?: Mode;
|
|
30
|
+
target?: Target;
|
|
31
|
+
entry: EntryConfig;
|
|
32
|
+
output: OutputConfig;
|
|
33
|
+
module: ModuleConfig;
|
|
34
|
+
options?: Options;
|
|
35
|
+
/**
|
|
36
|
+
* Modules to exclude from bundle.
|
|
37
|
+
*/
|
|
38
|
+
externalModules?: string[];
|
|
39
|
+
}
|
|
40
|
+
export interface OutputConfig {
|
|
41
|
+
name: string;
|
|
42
|
+
path: string;
|
|
43
|
+
}
|
|
44
|
+
export interface ModuleConfig {
|
|
45
|
+
}
|
|
46
|
+
export declare type Mode = 'production' | 'development' | 'none';
|
|
47
|
+
export declare type Target = 'browser' | 'node';
|
|
48
|
+
export declare type EntryConfig = string | string[] | {
|
|
49
|
+
[name: string]: string;
|
|
50
|
+
};
|
package/spack.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.config = exports.compileBundleOptions = void 0;
|
|
36
|
+
const path = __importStar(require("path"));
|
|
37
|
+
function compileBundleOptions(config) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const f = config === undefined ? '.' : config;
|
|
40
|
+
try {
|
|
41
|
+
const file = typeof f === 'string' ? f : path.resolve('spack.config.js');
|
|
42
|
+
let configFromFile = require(file);
|
|
43
|
+
if (configFromFile.default) {
|
|
44
|
+
configFromFile = configFromFile.default;
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(configFromFile)) {
|
|
47
|
+
if (Array.isArray(f)) {
|
|
48
|
+
return [...configFromFile, ...f];
|
|
49
|
+
}
|
|
50
|
+
if (typeof f !== 'string') {
|
|
51
|
+
configFromFile.push(f);
|
|
52
|
+
}
|
|
53
|
+
return configFromFile;
|
|
54
|
+
}
|
|
55
|
+
return Object.assign(Object.assign({}, configFromFile), (typeof config === 'string') ? {} : config);
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
if (typeof f === 'string') {
|
|
59
|
+
throw new Error(`Error occurred while loading config file at ${config}: ${e}`);
|
|
60
|
+
}
|
|
61
|
+
return f;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
exports.compileBundleOptions = compileBundleOptions;
|
|
66
|
+
/**
|
|
67
|
+
* Usage: In `spack.config.js` / `spack.config.ts`, you can utilize type annotations (to get autocompletions) like
|
|
68
|
+
*
|
|
69
|
+
* ```ts
|
|
70
|
+
* import { config } from '@swc/core/spack';
|
|
71
|
+
*
|
|
72
|
+
* export default config({
|
|
73
|
+
* name: 'web',
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
*
|
|
78
|
+
*
|
|
79
|
+
*/
|
|
80
|
+
function config(c) {
|
|
81
|
+
return c;
|
|
82
|
+
}
|
|
83
|
+
exports.config = config;
|