@shuvi/compiler 1.0.0-rc.10

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/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { transform, transformSync } from './swc';
2
+ export { transform, transformSync };
package/lib/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformSync = exports.transform = void 0;
4
+ const swc_1 = require("./swc");
5
+ Object.defineProperty(exports, "transform", { enumerable: true, get: function () { return swc_1.transform; } });
6
+ Object.defineProperty(exports, "transformSync", { enumerable: true, get: function () { return swc_1.transformSync; } });
@@ -0,0 +1,5 @@
1
+ export function transform(src: any, options: any): Promise<any>;
2
+ export function transformSync(src: any, options: any): any;
3
+ export function minify(src: any, opts: any): Promise<any>;
4
+ export function minifySync(src: any, opts: any): any;
5
+ export function bundle(options: any): Promise<any>;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.bundle = exports.minifySync = exports.minify = exports.transformSync = exports.transform = void 0;
13
+ const fs = require('fs');
14
+ const { platform, arch } = require('os');
15
+ const path = require('path');
16
+ const { platformArchTriples } = require('@napi-rs/triples');
17
+ const ArchName = arch();
18
+ const PlatformName = platform();
19
+ let bindings;
20
+ let loadError;
21
+ const triples = platformArchTriples[PlatformName][ArchName];
22
+ for (const triple of triples) {
23
+ try {
24
+ const swcSource = path.join(__dirname, '../../../compiler-swc/native');
25
+ const localFilePath = path.join(swcSource, `shuvi-swc.${triple.platformArchABI}.node`);
26
+ if (fs.existsSync(localFilePath)) {
27
+ console.log('Using locally built binary of shuvi-swc');
28
+ try {
29
+ bindings = require(localFilePath);
30
+ }
31
+ catch (e) {
32
+ if ((e === null || e === void 0 ? void 0 : e.code) !== 'MODULE_NOT_FOUND') {
33
+ loadError = e;
34
+ }
35
+ }
36
+ break;
37
+ }
38
+ else {
39
+ bindings = require(`@shuvi/swc-${triple.platformArchABI}`);
40
+ }
41
+ }
42
+ catch (e) {
43
+ loadError = e;
44
+ }
45
+ }
46
+ if (!bindings) {
47
+ if (loadError) {
48
+ console.error(loadError);
49
+ }
50
+ console.error(`Failed to load SWC binary`);
51
+ process.exit(1);
52
+ }
53
+ else {
54
+ loadError = null;
55
+ }
56
+ function transform(src, options) {
57
+ var _a, _b;
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const isModule = typeof src !== 'string' && !Buffer.isBuffer(src);
60
+ options = options || {};
61
+ if ((_a = options === null || options === void 0 ? void 0 : options.jsc) === null || _a === void 0 ? void 0 : _a.parser) {
62
+ options.jsc.parser.syntax = (_b = options.jsc.parser.syntax) !== null && _b !== void 0 ? _b : 'ecmascript';
63
+ }
64
+ return bindings.transform(isModule ? JSON.stringify(src) : src, isModule, toBuffer(options));
65
+ });
66
+ }
67
+ exports.transform = transform;
68
+ function transformSync(src, options) {
69
+ var _a, _b;
70
+ const isModule = typeof src !== 'string' && !Buffer.isBuffer(src);
71
+ options = options || {};
72
+ if ((_a = options === null || options === void 0 ? void 0 : options.jsc) === null || _a === void 0 ? void 0 : _a.parser) {
73
+ options.jsc.parser.syntax = (_b = options.jsc.parser.syntax) !== null && _b !== void 0 ? _b : 'ecmascript';
74
+ }
75
+ return bindings.transformSync(isModule ? JSON.stringify(src) : src, isModule, toBuffer(options));
76
+ }
77
+ exports.transformSync = transformSync;
78
+ function toBuffer(t) {
79
+ return Buffer.from(JSON.stringify(t));
80
+ }
81
+ function minify(src, opts) {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ return bindings.minify(toBuffer(src), toBuffer(opts !== null && opts !== void 0 ? opts : {}));
84
+ });
85
+ }
86
+ exports.minify = minify;
87
+ function minifySync(src, opts) {
88
+ return bindings.minifySync(toBuffer(src), toBuffer(opts !== null && opts !== void 0 ? opts : {}));
89
+ }
90
+ exports.minifySync = minifySync;
91
+ function bundle(options) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ return bindings.bundle(toBuffer(options));
94
+ });
95
+ }
96
+ exports.bundle = bundle;
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@shuvi/compiler",
3
+ "version": "1.0.0-rc.10",
4
+ "main": "./lib/index.js",
5
+ "types": "./lib/index.d.js",
6
+ "files": [
7
+ "lib"
8
+ ],
9
+ "scripts": {
10
+ "dev": "tsc -p tsconfig.build.json -w",
11
+ "prebuild": "rimraf lib",
12
+ "build": "tsc -p tsconfig.build.json"
13
+ },
14
+ "optionalDependencies": {
15
+ "@shuvi/swc-darwin-arm64": "1.0.0-rc.3",
16
+ "@shuvi/swc-darwin-x64": "1.0.0-rc.3",
17
+ "@shuvi/swc-linux-arm-gnueabihf": "1.0.0-rc.3",
18
+ "@shuvi/swc-linux-arm64-gnu": "1.0.0-rc.3",
19
+ "@shuvi/swc-linux-arm64-musl": "1.0.0-rc.3",
20
+ "@shuvi/swc-linux-x64-gnu": "1.0.0-rc.3",
21
+ "@shuvi/swc-linux-x64-musl": "1.0.0-rc.3",
22
+ "@shuvi/swc-win32-arm64-msvc": "1.0.0-rc.3",
23
+ "@shuvi/swc-win32-ia32-msvc": "1.0.0-rc.3",
24
+ "@shuvi/swc-win32-x64-msvc": "1.0.0-rc.3"
25
+ },
26
+ "dependencies": {
27
+ "@napi-rs/triples": "1.1.0"
28
+ },
29
+ "devDependencies": {
30
+ "@swc/plugin-transform-imports": "0.8.4"
31
+ }
32
+ }