@ttsc/unplugin 0.8.0 → 0.8.1
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 +21 -0
- package/README.md +9 -7
- package/lib/api.js +12 -18
- package/lib/api.js.map +1 -1
- package/lib/api.mjs +4 -0
- package/lib/api.mjs.map +1 -0
- package/lib/bun.js +12 -11
- package/lib/bun.js.map +1 -1
- package/lib/bun.mjs +31 -0
- package/lib/bun.mjs.map +1 -0
- package/lib/core/index.js +22 -17
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +42 -0
- package/lib/core/index.mjs.map +1 -0
- package/lib/core/options.js +5 -5
- package/lib/core/options.js.map +1 -1
- package/lib/core/options.mjs +14 -0
- package/lib/core/options.mjs.map +1 -0
- package/lib/core/transform.js +62 -73
- package/lib/core/transform.js.map +1 -1
- package/lib/core/transform.mjs +272 -0
- package/lib/core/transform.mjs.map +1 -0
- package/lib/esbuild.js +9 -8
- package/lib/esbuild.js.map +1 -1
- package/lib/esbuild.mjs +6 -0
- package/lib/esbuild.mjs.map +1 -0
- package/lib/farm.js +9 -8
- package/lib/farm.js.map +1 -1
- package/lib/farm.mjs +6 -0
- package/lib/farm.mjs.map +1 -0
- package/lib/index.js +10 -8
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +6 -0
- package/lib/index.mjs.map +1 -0
- package/lib/next.js +10 -9
- package/lib/next.js.map +1 -1
- package/lib/next.mjs +18 -0
- package/lib/next.mjs.map +1 -0
- package/lib/rolldown.js +9 -8
- package/lib/rolldown.js.map +1 -1
- package/lib/rolldown.mjs +6 -0
- package/lib/rolldown.mjs.map +1 -0
- package/lib/rollup.js +9 -8
- package/lib/rollup.js.map +1 -1
- package/lib/rollup.mjs +6 -0
- package/lib/rollup.mjs.map +1 -0
- package/lib/rspack.js +9 -8
- package/lib/rspack.js.map +1 -1
- package/lib/rspack.mjs +6 -0
- package/lib/rspack.mjs.map +1 -0
- package/lib/vite.js +9 -8
- package/lib/vite.js.map +1 -1
- package/lib/vite.mjs +6 -0
- package/lib/vite.mjs.map +1 -0
- package/lib/webpack.js +9 -8
- package/lib/webpack.js.map +1 -1
- package/lib/webpack.mjs +6 -0
- package/lib/webpack.mjs.map +1 -0
- package/package.json +31 -16
- package/src/core/index.ts +2 -0
- package/src/core/transform.ts +5 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jeongho Nam
|
|
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.
|
package/README.md
CHANGED
|
@@ -86,13 +86,13 @@ await build({
|
|
|
86
86
|
### Webpack
|
|
87
87
|
|
|
88
88
|
```js
|
|
89
|
-
// webpack.config.
|
|
90
|
-
|
|
89
|
+
// webpack.config.mjs
|
|
90
|
+
import ttsc from "@ttsc/unplugin/webpack";
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
export default {
|
|
93
93
|
entry: "./src/index.ts",
|
|
94
94
|
output: {
|
|
95
|
-
path:
|
|
95
|
+
path: new URL("./dist", import.meta.url).pathname,
|
|
96
96
|
},
|
|
97
97
|
plugins: [ttsc()],
|
|
98
98
|
};
|
|
@@ -101,10 +101,10 @@ module.exports = {
|
|
|
101
101
|
### Rspack
|
|
102
102
|
|
|
103
103
|
```js
|
|
104
|
-
// rspack.config.
|
|
105
|
-
|
|
104
|
+
// rspack.config.mjs
|
|
105
|
+
import ttsc from "@ttsc/unplugin/rspack";
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
export default {
|
|
108
108
|
entry: "./src/index.ts",
|
|
109
109
|
plugins: [ttsc()],
|
|
110
110
|
};
|
|
@@ -263,6 +263,8 @@ Supported entrypoints are:
|
|
|
263
263
|
- `@ttsc/unplugin/next`
|
|
264
264
|
- `@ttsc/unplugin/bun`
|
|
265
265
|
|
|
266
|
+
Each entrypoint supports ESM import and CJS require. In CommonJS configs, read the default export from `require("@ttsc/unplugin/vite").default`.
|
|
267
|
+
|
|
266
268
|
### Options
|
|
267
269
|
|
|
268
270
|
```ts
|
package/lib/api.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./core/index"), exports);
|
|
18
|
-
//# sourceMappingURL=api.js.map
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var index = require('./core/index.js');
|
|
4
|
+
var options = require('./core/options.js');
|
|
5
|
+
var transform = require('./core/transform.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.unplugin = index.default;
|
|
10
|
+
exports.resolveOptions = options.resolveOptions;
|
|
11
|
+
exports.transformTtsc = transform.transformTtsc;
|
|
12
|
+
//# sourceMappingURL=api.js.map
|
package/lib/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","
|
|
1
|
+
{"version":3,"file":"api.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
package/lib/api.mjs
ADDED
package/lib/api.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/lib/bun.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const api_1 = require("./api");
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var fs = require('node:fs/promises');
|
|
6
|
+
var index = require('./core/index.js');
|
|
7
|
+
|
|
9
8
|
const sourceFilePattern = /\.[cm]?[jt]sx?$/;
|
|
10
9
|
function bun(options) {
|
|
11
10
|
return {
|
|
12
11
|
name: "ttsc-unplugin",
|
|
13
12
|
setup(build) {
|
|
14
|
-
const raw =
|
|
13
|
+
const raw = index.default.raw(options, {});
|
|
15
14
|
build.onLoad({ filter: sourceFilePattern }, async (args) => {
|
|
16
|
-
const source = await
|
|
15
|
+
const source = await fs.readFile(args.path, "utf8");
|
|
17
16
|
const result = typeof raw.transform === "function"
|
|
18
17
|
? await raw.transform.call({}, source, args.path)
|
|
19
18
|
: undefined;
|
|
@@ -31,4 +30,6 @@ function bun(options) {
|
|
|
31
30
|
},
|
|
32
31
|
};
|
|
33
32
|
}
|
|
34
|
-
|
|
33
|
+
|
|
34
|
+
exports.default = bun;
|
|
35
|
+
//# sourceMappingURL=bun.js.map
|
package/lib/bun.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun.js","
|
|
1
|
+
{"version":3,"file":"bun.js","sources":["../src/bun.ts"],"sourcesContent":[null],"names":["unplugin"],"mappings":";;;;;;;AAkBA,MAAM,iBAAiB,GAAG,iBAAiB;AAE7B,SAAU,GAAG,CAAC,OAA6B,EAAA;IACvD,OAAO;AACL,QAAA,IAAI,EAAE,eAAe;AACrB,QAAA,KAAK,CAAC,KAAK,EAAA;YACT,MAAM,GAAG,GAAGA,aAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,EAAyB,CAAC;AAC5D,YAAA,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,EAAE,OAAO,IAAI,KAAI;AACzD,gBAAA,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC;AACnD,gBAAA,MAAM,MAAM,GACV,OAAO,GAAG,CAAC,SAAS,KAAK;AACvB,sBAAE,MAAM,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,EAAW,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI;sBACvD,SAAS;AACf,gBAAA,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;AAC9B,oBAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE;gBAC7B;gBACA,IACE,OAAO,MAAM,KAAK,QAAQ;AAC1B,oBAAA,MAAM,KAAK,IAAI;AACf,oBAAA,MAAM,IAAI,MAAM;AAChB,oBAAA,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,EAC/B;AACA,oBAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE;gBAClC;AACA,gBAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE;AAC7B,YAAA,CAAC,CAAC;QACJ,CAAC;KACF;AACH;;;;"}
|
package/lib/bun.mjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import unplugin from './core/index.mjs';
|
|
3
|
+
|
|
4
|
+
const sourceFilePattern = /\.[cm]?[jt]sx?$/;
|
|
5
|
+
function bun(options) {
|
|
6
|
+
return {
|
|
7
|
+
name: "ttsc-unplugin",
|
|
8
|
+
setup(build) {
|
|
9
|
+
const raw = unplugin.raw(options, {});
|
|
10
|
+
build.onLoad({ filter: sourceFilePattern }, async (args) => {
|
|
11
|
+
const source = await fs.readFile(args.path, "utf8");
|
|
12
|
+
const result = typeof raw.transform === "function"
|
|
13
|
+
? await raw.transform.call({}, source, args.path)
|
|
14
|
+
: undefined;
|
|
15
|
+
if (typeof result === "string") {
|
|
16
|
+
return { contents: result };
|
|
17
|
+
}
|
|
18
|
+
if (typeof result === "object" &&
|
|
19
|
+
result !== null &&
|
|
20
|
+
"code" in result &&
|
|
21
|
+
typeof result.code === "string") {
|
|
22
|
+
return { contents: result.code };
|
|
23
|
+
}
|
|
24
|
+
return { contents: source };
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { bun as default };
|
|
31
|
+
//# sourceMappingURL=bun.mjs.map
|
package/lib/bun.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bun.mjs","sources":["../src/bun.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAkBA,MAAM,iBAAiB,GAAG,iBAAiB;AAE7B,SAAU,GAAG,CAAC,OAA6B,EAAA;IACvD,OAAO;AACL,QAAA,IAAI,EAAE,eAAe;AACrB,QAAA,KAAK,CAAC,KAAK,EAAA;YACT,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,EAAyB,CAAC;AAC5D,YAAA,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,EAAE,OAAO,IAAI,KAAI;AACzD,gBAAA,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC;AACnD,gBAAA,MAAM,MAAM,GACV,OAAO,GAAG,CAAC,SAAS,KAAK;AACvB,sBAAE,MAAM,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,EAAW,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI;sBACvD,SAAS;AACf,gBAAA,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;AAC9B,oBAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE;gBAC7B;gBACA,IACE,OAAO,MAAM,KAAK,QAAQ;AAC1B,oBAAA,MAAM,KAAK,IAAI;AACf,oBAAA,MAAM,IAAI,MAAM;AAChB,oBAAA,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,EAC/B;AACA,oBAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE;gBAClC;AACA,gBAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE;AAC7B,YAAA,CAAC,CAAC;QACJ,CAAC;KACF;AACH;;;;"}
|
package/lib/core/index.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var unplugin$1 = require('unplugin');
|
|
6
|
+
var options = require('./options.js');
|
|
7
|
+
var transform = require('./transform.js');
|
|
8
|
+
|
|
9
9
|
const name = "ttsc-unplugin";
|
|
10
10
|
const sourceFilePattern = /\.[cm]?[jt]sx?$/;
|
|
11
11
|
const nodeModulesPattern = /(?:^|[/\\])node_modules(?:[/\\]|$)/;
|
|
12
|
+
const virtualModulePattern = /\0/;
|
|
12
13
|
const unpluginFactory = (rawOptions = {}) => {
|
|
13
|
-
const options =
|
|
14
|
+
const options$1 = options.resolveOptions(rawOptions);
|
|
14
15
|
let aliases;
|
|
15
16
|
return {
|
|
16
17
|
name,
|
|
@@ -21,24 +22,28 @@ const unpluginFactory = (rawOptions = {}) => {
|
|
|
21
22
|
},
|
|
22
23
|
},
|
|
23
24
|
transformInclude(id) {
|
|
24
|
-
const file =
|
|
25
|
+
const file = transform.stripQuery(id);
|
|
25
26
|
return isTransformTarget(file);
|
|
26
27
|
},
|
|
27
28
|
async transform(source, id) {
|
|
28
|
-
const file =
|
|
29
|
+
const file = transform.stripQuery(id);
|
|
29
30
|
if (!isTransformTarget(file)) {
|
|
30
31
|
return undefined;
|
|
31
32
|
}
|
|
32
|
-
return
|
|
33
|
+
return transform.transformTtsc(file, source, options$1, aliases);
|
|
33
34
|
},
|
|
34
35
|
};
|
|
35
36
|
};
|
|
36
|
-
const unplugin =
|
|
37
|
-
exports.unplugin = unplugin;
|
|
38
|
-
exports.default = unplugin;
|
|
37
|
+
const unplugin = unplugin$1.createUnplugin(unpluginFactory);
|
|
39
38
|
function isTransformTarget(id) {
|
|
40
39
|
return (sourceFilePattern.test(id) &&
|
|
41
|
-
!
|
|
40
|
+
!virtualModulePattern.test(id) &&
|
|
41
|
+
!transform.isDeclarationFile(id) &&
|
|
42
42
|
!nodeModulesPattern.test(id));
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
|
|
45
|
+
exports.resolveOptions = options.resolveOptions;
|
|
46
|
+
exports.transformTtsc = transform.transformTtsc;
|
|
47
|
+
exports.default = unplugin;
|
|
48
|
+
exports.unplugin = unplugin;
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
package/lib/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/core/index.ts"],"sourcesContent":[null],"names":["options","resolveOptions","stripQuery","transformTtsc","createUnplugin","isDeclarationFile"],"mappings":";;;;;;;;AAOA,MAAM,IAAI,GAAG,eAAe;AAC5B,MAAM,iBAAiB,GAAG,iBAAiB;AAC3C,MAAM,kBAAkB,GAAG,oCAAoC;AAC/D,MAAM,oBAAoB,GAAG,IAAI;AAEjC,MAAM,eAAe,GAGjB,CAAC,UAAU,GAAG,EAAE,KAAI;AACtB,IAAA,MAAMA,SAAO,GAAGC,sBAAc,CAAC,UAAU,CAAC;AAC1C,IAAA,IAAI,OAAgB;IAEpB,OAAO;QACL,IAAI;AACJ,QAAA,OAAO,EAAE,KAAK;AAEd,QAAA,IAAI,EAAE;AACJ,YAAA,cAAc,CAAC,MAAM,EAAA;AACnB,gBAAA,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK;YAChC,CAAC;AACF,SAAA;AAED,QAAA,gBAAgB,CAAC,EAAE,EAAA;AACjB,YAAA,MAAM,IAAI,GAAGC,oBAAU,CAAC,EAAE,CAAC;AAC3B,YAAA,OAAO,iBAAiB,CAAC,IAAI,CAAC;QAChC,CAAC;AAED,QAAA,MAAM,SAAS,CAAC,MAAM,EAAE,EAAE,EAAA;AACxB,YAAA,MAAM,IAAI,GAAGA,oBAAU,CAAC,EAAE,CAAC;AAC3B,YAAA,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE;AAC5B,gBAAA,OAAO,SAAS;YAClB;YACA,OAAOC,uBAAa,CAAC,IAAI,EAAE,MAAM,EAAEH,SAAO,EAAE,OAAO,CAAC;QACtD,CAAC;KACF;AACH,CAAC;AAED,MAAM,QAAQ,GACZI,yBAAc,CAAC,eAAe;AAUhC,SAAS,iBAAiB,CAAC,EAAU,EAAA;AACnC,IAAA,QACE,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;AAC1B,QAAA,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,CAACC,2BAAiB,CAAC,EAAE,CAAC;AACtB,QAAA,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;AAEhC;;;;;;;"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createUnplugin } from 'unplugin';
|
|
2
|
+
import { resolveOptions } from './options.mjs';
|
|
3
|
+
import { stripQuery, transformTtsc, isDeclarationFile } from './transform.mjs';
|
|
4
|
+
|
|
5
|
+
const name = "ttsc-unplugin";
|
|
6
|
+
const sourceFilePattern = /\.[cm]?[jt]sx?$/;
|
|
7
|
+
const nodeModulesPattern = /(?:^|[/\\])node_modules(?:[/\\]|$)/;
|
|
8
|
+
const virtualModulePattern = /\0/;
|
|
9
|
+
const unpluginFactory = (rawOptions = {}) => {
|
|
10
|
+
const options = resolveOptions(rawOptions);
|
|
11
|
+
let aliases;
|
|
12
|
+
return {
|
|
13
|
+
name,
|
|
14
|
+
enforce: "pre",
|
|
15
|
+
vite: {
|
|
16
|
+
configResolved(config) {
|
|
17
|
+
aliases = config.resolve.alias;
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
transformInclude(id) {
|
|
21
|
+
const file = stripQuery(id);
|
|
22
|
+
return isTransformTarget(file);
|
|
23
|
+
},
|
|
24
|
+
async transform(source, id) {
|
|
25
|
+
const file = stripQuery(id);
|
|
26
|
+
if (!isTransformTarget(file)) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
return transformTtsc(file, source, options, aliases);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
const unplugin = createUnplugin(unpluginFactory);
|
|
34
|
+
function isTransformTarget(id) {
|
|
35
|
+
return (sourceFilePattern.test(id) &&
|
|
36
|
+
!virtualModulePattern.test(id) &&
|
|
37
|
+
!isDeclarationFile(id) &&
|
|
38
|
+
!nodeModulesPattern.test(id));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { unplugin as default, resolveOptions, transformTtsc, unplugin };
|
|
42
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/core/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAOA,MAAM,IAAI,GAAG,eAAe;AAC5B,MAAM,iBAAiB,GAAG,iBAAiB;AAC3C,MAAM,kBAAkB,GAAG,oCAAoC;AAC/D,MAAM,oBAAoB,GAAG,IAAI;AAEjC,MAAM,eAAe,GAGjB,CAAC,UAAU,GAAG,EAAE,KAAI;AACtB,IAAA,MAAM,OAAO,GAAG,cAAc,CAAC,UAAU,CAAC;AAC1C,IAAA,IAAI,OAAgB;IAEpB,OAAO;QACL,IAAI;AACJ,QAAA,OAAO,EAAE,KAAK;AAEd,QAAA,IAAI,EAAE;AACJ,YAAA,cAAc,CAAC,MAAM,EAAA;AACnB,gBAAA,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK;YAChC,CAAC;AACF,SAAA;AAED,QAAA,gBAAgB,CAAC,EAAE,EAAA;AACjB,YAAA,MAAM,IAAI,GAAG,UAAU,CAAC,EAAE,CAAC;AAC3B,YAAA,OAAO,iBAAiB,CAAC,IAAI,CAAC;QAChC,CAAC;AAED,QAAA,MAAM,SAAS,CAAC,MAAM,EAAE,EAAE,EAAA;AACxB,YAAA,MAAM,IAAI,GAAG,UAAU,CAAC,EAAE,CAAC;AAC3B,YAAA,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE;AAC5B,gBAAA,OAAO,SAAS;YAClB;YACA,OAAO,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC;QACtD,CAAC;KACF;AACH,CAAC;AAED,MAAM,QAAQ,GACZ,cAAc,CAAC,eAAe;AAUhC,SAAS,iBAAiB,CAAC,EAAU,EAAA;AACnC,IAAA,QACE,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;AAC1B,QAAA,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,CAAC,iBAAiB,CAAC,EAAE,CAAC;AACtB,QAAA,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;AAEhC;;;;"}
|
package/lib/core/options.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.resolveOptions = resolveOptions;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
4
3
|
const defaultOptions = {
|
|
5
|
-
compilerOptions: {},
|
|
6
4
|
plugins: undefined,
|
|
7
5
|
project: undefined,
|
|
8
6
|
};
|
|
@@ -13,4 +11,6 @@ function resolveOptions(options = {}) {
|
|
|
13
11
|
project: options.project ?? defaultOptions.project,
|
|
14
12
|
};
|
|
15
13
|
}
|
|
16
|
-
|
|
14
|
+
|
|
15
|
+
exports.resolveOptions = resolveOptions;
|
|
16
|
+
//# sourceMappingURL=options.js.map
|
package/lib/core/options.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","
|
|
1
|
+
{"version":3,"file":"options.js","sources":["../../src/core/options.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAqCA,MAAM,cAAc,GAAgC;AAClD,IACA,OAAO,EAAE,SAAS;AAClB,IAAA,OAAO,EAAE,SAAS;CACnB;AAEK,SAAU,cAAc,CAC5B,OAAA,GAA+B,EAAE,EAAA;IAEjC,OAAO;QACL,eAAe,EAAE,EAAE,IAAI,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC,EAAE;AACvD,QAAA,OAAO,EAAE,SAAS,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,GAAG,cAAc,CAAC,OAAO;AACxE,QAAA,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,cAAc,CAAC,OAAO;KACnD;AACH;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const defaultOptions = {
|
|
2
|
+
plugins: undefined,
|
|
3
|
+
project: undefined,
|
|
4
|
+
};
|
|
5
|
+
function resolveOptions(options = {}) {
|
|
6
|
+
return {
|
|
7
|
+
compilerOptions: { ...(options.compilerOptions ?? {}) },
|
|
8
|
+
plugins: "plugins" in options ? options.plugins : defaultOptions.plugins,
|
|
9
|
+
project: options.project ?? defaultOptions.project,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { resolveOptions };
|
|
14
|
+
//# sourceMappingURL=options.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.mjs","sources":["../../src/core/options.ts"],"sourcesContent":[null],"names":[],"mappings":"AAqCA,MAAM,cAAc,GAAgC;AAClD,IACA,OAAO,EAAE,SAAS;AAClB,IAAA,OAAO,EAAE,SAAS;CACnB;AAEK,SAAU,cAAc,CAC5B,OAAA,GAA+B,EAAE,EAAA;IAEjC,OAAO;QACL,eAAe,EAAE,EAAE,IAAI,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC,EAAE;AACvD,QAAA,OAAO,EAAE,SAAS,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,GAAG,cAAc,CAAC,OAAO;AACxE,QAAA,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,cAAc,CAAC,OAAO;KACnD;AACH;;;;"}
|
package/lib/core/transform.js
CHANGED
|
@@ -1,57 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Diff = require('diff-match-patch-es');
|
|
4
|
+
var fs = require('node:fs');
|
|
5
|
+
var path = require('node:path');
|
|
6
|
+
var MagicString = require('magic-string');
|
|
7
|
+
var ttsc = require('ttsc');
|
|
8
|
+
|
|
9
|
+
function _interopNamespaceDefault(e) {
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
7
21
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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 () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.transformTtsc = transformTtsc;
|
|
40
|
-
exports.stripQuery = stripQuery;
|
|
41
|
-
exports.isDeclarationFile = isDeclarationFile;
|
|
42
|
-
exports.createTransformResult = createTransformResult;
|
|
43
|
-
const Diff = __importStar(require("diff-match-patch-es"));
|
|
44
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
45
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
46
|
-
const magic_string_1 = __importDefault(require("magic-string"));
|
|
47
|
-
const ttsc_1 = require("ttsc");
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var Diff__namespace = /*#__PURE__*/_interopNamespaceDefault(Diff);
|
|
27
|
+
|
|
48
28
|
async function transformTtsc(id, source, options, aliases) {
|
|
49
|
-
const
|
|
29
|
+
const clean = stripQuery(id);
|
|
30
|
+
if (clean.includes("\0")) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
const file = path.resolve(clean);
|
|
50
34
|
if (isDeclarationFile(file)) {
|
|
51
35
|
return undefined;
|
|
52
36
|
}
|
|
53
37
|
const tsconfig = resolveTsconfig(file, options.project);
|
|
54
|
-
const tsconfigDir =
|
|
38
|
+
const tsconfigDir = path.dirname(tsconfig);
|
|
55
39
|
const baseUrl = resolveBaseUrl(tsconfigDir, options.compilerOptions);
|
|
56
40
|
const aliasPaths = createAliasPaths(baseUrl, aliases);
|
|
57
41
|
const configured = createTransformTsconfig({
|
|
@@ -62,14 +46,14 @@ async function transformTtsc(id, source, options, aliases) {
|
|
|
62
46
|
});
|
|
63
47
|
try {
|
|
64
48
|
const effectiveTsconfig = configured.path;
|
|
65
|
-
const result = new
|
|
66
|
-
cwd:
|
|
49
|
+
const result = new ttsc.TtscCompiler({
|
|
50
|
+
cwd: path.dirname(effectiveTsconfig),
|
|
67
51
|
plugins: options.plugins,
|
|
68
52
|
tsconfig: effectiveTsconfig,
|
|
69
53
|
}).transform();
|
|
70
54
|
const code = selectTransformedSource({
|
|
71
55
|
file,
|
|
72
|
-
projectRoot:
|
|
56
|
+
projectRoot: path.dirname(effectiveTsconfig),
|
|
73
57
|
result,
|
|
74
58
|
});
|
|
75
59
|
return createTransformResult(source, code, file);
|
|
@@ -92,9 +76,9 @@ function createTransformResult(source, code, id) {
|
|
|
92
76
|
if (source === code) {
|
|
93
77
|
return undefined;
|
|
94
78
|
}
|
|
95
|
-
const magic = new
|
|
96
|
-
const diff =
|
|
97
|
-
|
|
79
|
+
const magic = new MagicString(source);
|
|
80
|
+
const diff = Diff__namespace.diff(source, code);
|
|
81
|
+
Diff__namespace.diffCleanupSemantic(diff);
|
|
98
82
|
let offset = 0;
|
|
99
83
|
for (let index = 0; index < diff.length; index += 1) {
|
|
100
84
|
const [type, text] = diff[index];
|
|
@@ -139,17 +123,17 @@ function createTransformTsconfig(props) {
|
|
|
139
123
|
dispose: () => undefined,
|
|
140
124
|
};
|
|
141
125
|
}
|
|
142
|
-
const directory =
|
|
143
|
-
const file =
|
|
126
|
+
const directory = path.dirname(props.tsconfig);
|
|
127
|
+
const file = path.join(directory, `.ttsc-unplugin-${process.pid}-${Date.now()}-${Math.random()
|
|
144
128
|
.toString(36)
|
|
145
129
|
.slice(2)}.json`);
|
|
146
|
-
|
|
147
|
-
extends: `./${
|
|
130
|
+
fs.writeFileSync(file, JSON.stringify({
|
|
131
|
+
extends: `./${path.basename(props.tsconfig)}`,
|
|
148
132
|
compilerOptions,
|
|
149
133
|
}, null, 2), "utf8");
|
|
150
134
|
return {
|
|
151
135
|
path: file,
|
|
152
|
-
dispose: () =>
|
|
136
|
+
dispose: () => fs.rmSync(file, { force: true }),
|
|
153
137
|
};
|
|
154
138
|
}
|
|
155
139
|
function createAliasCompilerOptions(props) {
|
|
@@ -182,7 +166,7 @@ function readPaths(value) {
|
|
|
182
166
|
}
|
|
183
167
|
function resolveBaseUrl(tsconfigDir, compilerOptions) {
|
|
184
168
|
return typeof compilerOptions.baseUrl === "string"
|
|
185
|
-
?
|
|
169
|
+
? path.resolve(tsconfigDir, compilerOptions.baseUrl)
|
|
186
170
|
: tsconfigDir;
|
|
187
171
|
}
|
|
188
172
|
function toCompilerPath(absoluteBaseUrl, compilerOptions) {
|
|
@@ -203,10 +187,10 @@ function createAliasPaths(baseUrl, aliases) {
|
|
|
203
187
|
if (key.length === 0) {
|
|
204
188
|
continue;
|
|
205
189
|
}
|
|
206
|
-
const replacement =
|
|
190
|
+
const replacement = path.isAbsolute(alias.replacement)
|
|
207
191
|
? alias.replacement
|
|
208
|
-
:
|
|
209
|
-
const target = normalizePath(
|
|
192
|
+
: path.resolve(process.cwd(), alias.replacement);
|
|
193
|
+
const target = normalizePath(path.relative(baseUrl, replacement) || ".");
|
|
210
194
|
paths[key] = [target];
|
|
211
195
|
paths[`${key}/*`] = [`${target}/*`];
|
|
212
196
|
}
|
|
@@ -244,7 +228,7 @@ function selectTransformedSource(props) {
|
|
|
244
228
|
return direct;
|
|
245
229
|
}
|
|
246
230
|
for (const [candidate, source] of Object.entries(props.result.typescript)) {
|
|
247
|
-
if (
|
|
231
|
+
if (path.resolve(props.projectRoot, candidate) === props.file) {
|
|
248
232
|
return source;
|
|
249
233
|
}
|
|
250
234
|
}
|
|
@@ -280,28 +264,33 @@ function formatUnknownError(error) {
|
|
|
280
264
|
}
|
|
281
265
|
function resolveTsconfig(file, tsconfig) {
|
|
282
266
|
if (tsconfig !== undefined) {
|
|
283
|
-
return
|
|
267
|
+
return path.isAbsolute(tsconfig)
|
|
284
268
|
? tsconfig
|
|
285
|
-
:
|
|
269
|
+
: path.resolve(process.cwd(), tsconfig);
|
|
286
270
|
}
|
|
287
|
-
let current =
|
|
271
|
+
let current = path.dirname(file);
|
|
288
272
|
while (true) {
|
|
289
|
-
const candidate =
|
|
290
|
-
if (
|
|
273
|
+
const candidate = path.join(current, "tsconfig.json");
|
|
274
|
+
if (fs.existsSync(candidate)) {
|
|
291
275
|
return candidate;
|
|
292
276
|
}
|
|
293
|
-
const parent =
|
|
277
|
+
const parent = path.dirname(current);
|
|
294
278
|
if (parent === current) {
|
|
295
279
|
break;
|
|
296
280
|
}
|
|
297
281
|
current = parent;
|
|
298
282
|
}
|
|
299
|
-
return
|
|
283
|
+
return path.resolve(process.cwd(), "tsconfig.json");
|
|
300
284
|
}
|
|
301
285
|
function toProjectKey(root, file) {
|
|
302
|
-
return normalizePath(
|
|
286
|
+
return normalizePath(path.relative(root, file));
|
|
303
287
|
}
|
|
304
288
|
function normalizePath(file) {
|
|
305
289
|
return file.replace(/\\/g, "/");
|
|
306
290
|
}
|
|
307
|
-
|
|
291
|
+
|
|
292
|
+
exports.createTransformResult = createTransformResult;
|
|
293
|
+
exports.isDeclarationFile = isDeclarationFile;
|
|
294
|
+
exports.stripQuery = stripQuery;
|
|
295
|
+
exports.transformTtsc = transformTtsc;
|
|
296
|
+
//# sourceMappingURL=transform.js.map
|