@ttsc/unplugin 0.30.2 → 0.30.3
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/bun.js +3 -16
- package/lib/bun.js.map +1 -1
- package/lib/bun.mjs +3 -16
- package/lib/bun.mjs.map +1 -1
- package/lib/core/esbuild.d.cts +4 -0
- package/lib/core/esbuild.d.mts +4 -0
- package/lib/core/esbuild.d.ts +4 -0
- package/lib/core/esbuild.js +110 -0
- package/lib/core/esbuild.js.map +1 -0
- package/lib/core/esbuild.mjs +108 -0
- package/lib/core/esbuild.mjs.map +1 -0
- package/lib/core/index.js +49 -89
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +50 -90
- package/lib/core/index.mjs.map +1 -1
- package/lib/core/transform.d.cts +5 -3
- package/lib/core/transform.d.mts +5 -3
- package/lib/core/transform.d.ts +5 -3
- package/lib/core/transform.js +25 -25
- package/lib/core/transform.js.map +1 -1
- package/lib/core/transform.mjs +25 -25
- package/lib/core/transform.mjs.map +1 -1
- package/lib/core/viteServe.d.cts +16 -38
- package/lib/core/viteServe.d.mts +16 -38
- package/lib/core/viteServe.d.ts +16 -38
- package/lib/core/viteServe.js +234 -98
- package/lib/core/viteServe.js.map +1 -1
- package/lib/core/viteServe.mjs +235 -98
- package/lib/core/viteServe.mjs.map +1 -1
- package/package.json +4 -3
- package/src/bun.ts +2 -17
- package/src/core/esbuild.ts +127 -0
- package/src/core/index.ts +51 -100
- package/src/core/transform.ts +30 -28
- package/src/core/viteServe.ts +275 -164
package/lib/bun.js
CHANGED
|
@@ -8,21 +8,6 @@ var sourceExtensions = require('./core/sourceExtensions.js');
|
|
|
8
8
|
var transform = require('./core/transform.js');
|
|
9
9
|
var options = require('./core/options.js');
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Transform hooks handed to the shared transform under Bun.
|
|
13
|
-
*
|
|
14
|
-
* The shared transform calls `addWatchFile` once per plugin-reported dependency
|
|
15
|
-
* so type-only inputs can enter a bundler's watch graph. Bun's bundler and
|
|
16
|
-
* runtime loaders expose no per-module dependency-registration channel, so the
|
|
17
|
-
* hook is an explicit no-op here: reported dependencies cannot participate in
|
|
18
|
-
* Bun invalidation, but a valid dependency list must never crash the loader by
|
|
19
|
-
* reaching a missing context method. Passing an empty object made
|
|
20
|
-
* `this.addWatchFile` `undefined`, so any plugin reporting dependencies threw
|
|
21
|
-
* `TypeError: this.addWatchFile is not a function`.
|
|
22
|
-
*/
|
|
23
|
-
const bunTransformHooks = {
|
|
24
|
-
addWatchFile() { },
|
|
25
|
-
};
|
|
26
11
|
/** Resolve {@link TtscBunOptions} to a plain options object (or `undefined`). */
|
|
27
12
|
function resolveBunOptions(options) {
|
|
28
13
|
return typeof options === "function" ? options() : options;
|
|
@@ -88,7 +73,9 @@ function bun(options$1) {
|
|
|
88
73
|
const loader = bunLoaderFor(args.path);
|
|
89
74
|
const transformOptions = getOptions();
|
|
90
75
|
const source = await fs.readFile(args.path, "utf8");
|
|
91
|
-
|
|
76
|
+
// Bun has no dependency subscription API. Omitting watch hooks also
|
|
77
|
+
// avoids deriving a filesystem watch graph that this host cannot use.
|
|
78
|
+
const result = await transform.transformTtsc(args.path, source, transformOptions, undefined, cache);
|
|
92
79
|
if (result !== undefined) {
|
|
93
80
|
return { contents: result.code, loader };
|
|
94
81
|
}
|
package/lib/bun.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun.js","sources":["../src/bun.ts"],"sourcesContent":[null],"names":["options","resolveOptions","createTtscTransformCache","beginTtscTransformBuild","resetTtscTransformCache","bunTypeScriptTransformSourcePattern","isTransformTarget","transformTtsc","typescriptTransformBunLoader"],"mappings":";;;;;;;;;;AAgDA
|
|
1
|
+
{"version":3,"file":"bun.js","sources":["../src/bun.ts"],"sourcesContent":[null],"names":["options","resolveOptions","createTtscTransformCache","beginTtscTransformBuild","resetTtscTransformCache","bunTypeScriptTransformSourcePattern","isTransformTarget","transformTts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BAAkB,CAAC,CAAC;AACtE,IAAA,OAAO,CAAC,IAAI,KAAK,UAAU,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;AAC3D;AAEA;;;;;;AAMG;AACH,SAAS,kBAAkB,CAAC,IAAY,EAAA;AACtC,IAAA,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;AAAE,QAAA,OAAO,IAAI;AAC7C,IAAA,OAAO;AACJ,SAAA,OAAO,CAAC,KAAK,EAAE,GAAG;AAClB,SAAA,OAAO,CACN,YAAY,EACZ,CAAC,MAAM,EAAE,KAAa,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE,CAAA,CAAA,CAAG,CACrD;AACL;;;;"}
|
package/lib/bun.mjs
CHANGED
|
@@ -4,21 +4,6 @@ import { bunTypeScriptTransformSourcePattern, typescriptTransformBunLoader } fro
|
|
|
4
4
|
import { createTtscTransformCache, beginTtscTransformBuild, resetTtscTransformCache, transformTtsc } from './core/transform.mjs';
|
|
5
5
|
import { resolveOptions } from './core/options.mjs';
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Transform hooks handed to the shared transform under Bun.
|
|
9
|
-
*
|
|
10
|
-
* The shared transform calls `addWatchFile` once per plugin-reported dependency
|
|
11
|
-
* so type-only inputs can enter a bundler's watch graph. Bun's bundler and
|
|
12
|
-
* runtime loaders expose no per-module dependency-registration channel, so the
|
|
13
|
-
* hook is an explicit no-op here: reported dependencies cannot participate in
|
|
14
|
-
* Bun invalidation, but a valid dependency list must never crash the loader by
|
|
15
|
-
* reaching a missing context method. Passing an empty object made
|
|
16
|
-
* `this.addWatchFile` `undefined`, so any plugin reporting dependencies threw
|
|
17
|
-
* `TypeError: this.addWatchFile is not a function`.
|
|
18
|
-
*/
|
|
19
|
-
const bunTransformHooks = {
|
|
20
|
-
addWatchFile() { },
|
|
21
|
-
};
|
|
22
7
|
/** Resolve {@link TtscBunOptions} to a plain options object (or `undefined`). */
|
|
23
8
|
function resolveBunOptions(options) {
|
|
24
9
|
return typeof options === "function" ? options() : options;
|
|
@@ -84,7 +69,9 @@ function bun(options) {
|
|
|
84
69
|
const loader = bunLoaderFor(args.path);
|
|
85
70
|
const transformOptions = getOptions();
|
|
86
71
|
const source = await fs.readFile(args.path, "utf8");
|
|
87
|
-
|
|
72
|
+
// Bun has no dependency subscription API. Omitting watch hooks also
|
|
73
|
+
// avoids deriving a filesystem watch graph that this host cannot use.
|
|
74
|
+
const result = await transformTtsc(args.path, source, transformOptions, undefined, cache);
|
|
88
75
|
if (result !== undefined) {
|
|
89
76
|
return { contents: result.code, loader };
|
|
90
77
|
}
|
package/lib/bun.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun.mjs","sources":["../src/bun.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AAgDA
|
|
1
|
+
{"version":3,"file":"bun.mjs","sources":["../src/bun.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AAgDA;AACA,SAAS,iBAAiB,CACxB,OAAwB,EAAA;AAExB,IAAA,OAAO,OAAO,OAAO,KAAK,UAAU,GAAG,OAAO,EAAE,GAAG,OAAO;AAC5D;AA+CA;;;;;;;;;;;;;;;;;;;;;AAqBG;AACW,SAAU,GAAG,CAAC,OAAwB,EAAA;IAClD,OAAO;AACL,QAAA,IAAI,EAAE,eAAe;AACrB,QAAA,KAAK,CAAC,KAAK,EAAA;;;;;AAKT,YAAA,IAAI,QAAuD;AAC3D,YAAA,MAAM,UAAU,GAAG,OAChB,QAAQ,KAAK,cAAc,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC;AAC3D,YAAA,MAAM,KAAK,GAAG,wBAAwB,EAAE;AACxC,YAAA,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,KAAK,SAAS;AAC3C,YAAA,MAAM,gBAAgB,GAAG,4BAA4B,CAAC,KAAK,CAAC;;;;;;;YAO5D,uBAAuB,CAAC,KAAK,CAAC;AAC9B,YAAA,KAAK,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ACF;AACH;AAEA;;;;AAIG;AACH,SAAS,YAAY,CAAC,QAAgB,EAAA;AACpC,IAAA,MAAM,MAAM,GAAG,4BAA4B,CAAC,QAAQ,CAAC;AACrD,IAAA,IAAI,MAAM,KAAK,SAAS,EAAE;AACxB,QAAA,MAAM,IAAI,KAAK,CAAC,6CAA6C,QAAQ,CAAA,CAAE,CAAC;IAC1E;AACA,IAAA,OAAO,MAAM;AACf;AAEA;;;;;;;AAOG;AACH,SAAS,4BAA4B,CACnC,KAAmB,EAAA;AAEnB,IAAA,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK;IACjC,IAAI,KAAK,KAAK,SAAS;AAAE,QAAA,OAAO,MAAM,KAAK;AAC3C,IAAA,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;AACtE,IAAA,OAAO,CAAC,IAAI,KAAK,UAAU,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;AAC3D;AAEA;;;;;;AAMG;AACH,SAAS,kBAAkB,CAAC,IAAY,EAAA;AACtC,IAAA,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;AAAE,QAAA,OAAO,IAAI;AAC7C,IAAA,OAAO;AACJ,SAAA,OAAO,CAAC,KAAK,EAAE,GAAG;AAClB,SAAA,OAAO,CACN,YAAY,EACZ,CAAC,MAAM,EAAE,KAAa,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE,CAAA,CAAA,CAAG,CACrD;AACL;;;;"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { UnpluginOptions } from "unplugin";
|
|
2
|
+
import type { ResolvedTtscUnpluginOptions } from "./options.cjs";
|
|
3
|
+
/** Preserve esbuild's distinct file and directory dependency channels. */
|
|
4
|
+
export declare function createEsbuildOptions(options: ResolvedTtscUnpluginOptions, includes: (file: string) => boolean): UnpluginOptions;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { UnpluginOptions } from "unplugin";
|
|
2
|
+
import type { ResolvedTtscUnpluginOptions } from "./options.mjs";
|
|
3
|
+
/** Preserve esbuild's distinct file and directory dependency channels. */
|
|
4
|
+
export declare function createEsbuildOptions(options: ResolvedTtscUnpluginOptions, includes: (file: string) => boolean): UnpluginOptions;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { UnpluginOptions } from "unplugin";
|
|
2
|
+
import type { ResolvedTtscUnpluginOptions } from "./options";
|
|
3
|
+
/** Preserve esbuild's distinct file and directory dependency channels. */
|
|
4
|
+
export declare function createEsbuildOptions(options: ResolvedTtscUnpluginOptions, includes: (file: string) => boolean): UnpluginOptions;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('node:fs');
|
|
4
|
+
var path = require('node:path');
|
|
5
|
+
var sourceExtensions = require('./sourceExtensions.js');
|
|
6
|
+
var transform = require('./transform.js');
|
|
7
|
+
|
|
8
|
+
/** Preserve esbuild's distinct file and directory dependency channels. */
|
|
9
|
+
function createEsbuildOptions(options, includes) {
|
|
10
|
+
const cache = transform.createTtscTransformCache();
|
|
11
|
+
const owners = new WeakSet();
|
|
12
|
+
let lifecycles = 0;
|
|
13
|
+
return {
|
|
14
|
+
name: "ttsc-unplugin",
|
|
15
|
+
esbuild: {
|
|
16
|
+
setup(build) {
|
|
17
|
+
// Setup can fail validation without receiving onDispose. Acquire only
|
|
18
|
+
// at onStart, and retain a generation while another owner is active.
|
|
19
|
+
build.onStart(() => {
|
|
20
|
+
if (!owners.has(build)) {
|
|
21
|
+
owners.add(build);
|
|
22
|
+
lifecycles += 1;
|
|
23
|
+
}
|
|
24
|
+
transform.beginTtscTransformBuild(cache);
|
|
25
|
+
});
|
|
26
|
+
build.onDispose(() => {
|
|
27
|
+
if (!owners.delete(build))
|
|
28
|
+
return;
|
|
29
|
+
lifecycles -= 1;
|
|
30
|
+
if (lifecycles === 0)
|
|
31
|
+
transform.resetTtscTransformCache(cache);
|
|
32
|
+
});
|
|
33
|
+
const previous = new Map();
|
|
34
|
+
// There is no generic transform hook on this adapter. Its native
|
|
35
|
+
// loader owns registration, independent of unplugin's hook order.
|
|
36
|
+
build.onLoad({ filter: sourceExtensions.typescriptTransformSourcePattern, namespace: "file" }, async ({ path: file }) => {
|
|
37
|
+
if (!includes(file))
|
|
38
|
+
return;
|
|
39
|
+
const watchFiles = new Set([file]);
|
|
40
|
+
const watchDirs = new Set();
|
|
41
|
+
const register = (inputs) => {
|
|
42
|
+
for (const input of inputs) {
|
|
43
|
+
const observation = input.evidence?.state?.codec === "predicates"
|
|
44
|
+
? input.evidence.state.observation
|
|
45
|
+
: undefined;
|
|
46
|
+
const directory = observation?.directoryExists === true ||
|
|
47
|
+
observation?.stat === "directory" ||
|
|
48
|
+
observation?.accessibleEntries !== undefined;
|
|
49
|
+
const missingDirectory = observation?.directoryExists === false &&
|
|
50
|
+
observation.fileExists !== true &&
|
|
51
|
+
observation.stat !== "file";
|
|
52
|
+
if (directory || missingDirectory)
|
|
53
|
+
watchDirs.add(input.file);
|
|
54
|
+
if (!directory || observation?.fileExists !== undefined)
|
|
55
|
+
watchFiles.add(input.file);
|
|
56
|
+
// Failed envelopes carry no generation evidence. This rare
|
|
57
|
+
// path must still classify existing recovery directories.
|
|
58
|
+
if (input.evidence === undefined) {
|
|
59
|
+
try {
|
|
60
|
+
if (fs.statSync(input.file).isDirectory())
|
|
61
|
+
watchDirs.add(input.file);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// Missing files are already tracked through watchFiles.
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
let contents;
|
|
70
|
+
let errors;
|
|
71
|
+
try {
|
|
72
|
+
const source = await fs.promises.readFile(file, "utf8");
|
|
73
|
+
const result = await transform.transformTtsc(file, source, options, undefined, cache, { addWatchFiles: register });
|
|
74
|
+
contents = result?.code ?? source;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
for (const input of previous.get(file)?.watchFiles ?? [])
|
|
78
|
+
watchFiles.add(input);
|
|
79
|
+
for (const input of previous.get(file)?.watchDirs ?? [])
|
|
80
|
+
watchDirs.add(input);
|
|
81
|
+
// Returning errors with dependencies lets an initially failing
|
|
82
|
+
// build observe its repair; throwing discards those channels.
|
|
83
|
+
errors = [
|
|
84
|
+
{
|
|
85
|
+
text: error instanceof Error ? error.message : String(error),
|
|
86
|
+
detail: error,
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
contents = "";
|
|
90
|
+
}
|
|
91
|
+
const dependencies = {
|
|
92
|
+
watchFiles: [...watchFiles],
|
|
93
|
+
watchDirs: [...watchDirs],
|
|
94
|
+
};
|
|
95
|
+
previous.set(file, dependencies);
|
|
96
|
+
return {
|
|
97
|
+
contents,
|
|
98
|
+
errors,
|
|
99
|
+
loader: file.endsWith(".tsx") ? "tsx" : "ts",
|
|
100
|
+
resolveDir: path.dirname(file),
|
|
101
|
+
...dependencies,
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
exports.createEsbuildOptions = createEsbuildOptions;
|
|
110
|
+
//# sourceMappingURL=esbuild.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild.js","sources":["../../src/core/esbuild.ts"],"sourcesContent":[null],"names":["createTtscTransformCache","beginTtscTransformBuild","resetTtscTransformCache","typescriptTransformSourcePattern","transformTtsc"],"mappings":";;;;;;;AAcA;AACM,SAAU,oBAAoB,CAClC,OAAoC,EACpC,QAAmC,EAAA;AAEnC,IAAA,MAAM,KAAK,GAAGA,kCAAwB,EAAE;AACxC,IAAA,MAAM,MAAM,GAAG,IAAI,OAAO,EAAU;IACpC,IAAI,UAAU,GAAG,CAAC;IAClB,OAAO;AACL,QAA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A,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC;AACvB,wBAAA,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,SAAS,IAAI,EAAE;AACrD,4BAAA,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC;;;AAGtB,wBAAA,MAAM,GAAG;AACP,4BAAA;AACE,gCAAA,IAAI,EAAE,KAAK,YAAY,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC;AAC5D,gCAAA,MAAM,EAAE,KAAK;AACd,6BAAA;yBACF;wBACD,QAAQ,GAAG,EAAE;oBACf;AACA,oBAAA,MAAM,YAAY,GAAG;AACnB,wBAAA,UAAU,EAAE,CAAC,GAAG,UAAU,CAAC;AAC3B,wBAAA,SAAS,EAAE,CAAC,GAAG,SAAS,CAAC;qBAC1B;AACD,oBAAA,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,YAAY,CAAC;oBAChC,OAAO;wBACL,QAAQ;wBACR,MAAM;AACN,wBAAA,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,KAAK,GAAG,IAAI;AAC5C,wBAAA,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;AAC9B,wBAAA,GAAG,YAAY;qBAChB;AACH,gBAAA,CAAC,CACF;YACH,CAAC;AACF,SAAA;KACF;AACH;;;;"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { typescriptTransformSourcePattern } from './sourceExtensions.mjs';
|
|
4
|
+
import { createTtscTransformCache, beginTtscTransformBuild, resetTtscTransformCache, transformTtsc } from './transform.mjs';
|
|
5
|
+
|
|
6
|
+
/** Preserve esbuild's distinct file and directory dependency channels. */
|
|
7
|
+
function createEsbuildOptions(options, includes) {
|
|
8
|
+
const cache = createTtscTransformCache();
|
|
9
|
+
const owners = new WeakSet();
|
|
10
|
+
let lifecycles = 0;
|
|
11
|
+
return {
|
|
12
|
+
name: "ttsc-unplugin",
|
|
13
|
+
esbuild: {
|
|
14
|
+
setup(build) {
|
|
15
|
+
// Setup can fail validation without receiving onDispose. Acquire only
|
|
16
|
+
// at onStart, and retain a generation while another owner is active.
|
|
17
|
+
build.onStart(() => {
|
|
18
|
+
if (!owners.has(build)) {
|
|
19
|
+
owners.add(build);
|
|
20
|
+
lifecycles += 1;
|
|
21
|
+
}
|
|
22
|
+
beginTtscTransformBuild(cache);
|
|
23
|
+
});
|
|
24
|
+
build.onDispose(() => {
|
|
25
|
+
if (!owners.delete(build))
|
|
26
|
+
return;
|
|
27
|
+
lifecycles -= 1;
|
|
28
|
+
if (lifecycles === 0)
|
|
29
|
+
resetTtscTransformCache(cache);
|
|
30
|
+
});
|
|
31
|
+
const previous = new Map();
|
|
32
|
+
// There is no generic transform hook on this adapter. Its native
|
|
33
|
+
// loader owns registration, independent of unplugin's hook order.
|
|
34
|
+
build.onLoad({ filter: typescriptTransformSourcePattern, namespace: "file" }, async ({ path: file }) => {
|
|
35
|
+
if (!includes(file))
|
|
36
|
+
return;
|
|
37
|
+
const watchFiles = new Set([file]);
|
|
38
|
+
const watchDirs = new Set();
|
|
39
|
+
const register = (inputs) => {
|
|
40
|
+
for (const input of inputs) {
|
|
41
|
+
const observation = input.evidence?.state?.codec === "predicates"
|
|
42
|
+
? input.evidence.state.observation
|
|
43
|
+
: undefined;
|
|
44
|
+
const directory = observation?.directoryExists === true ||
|
|
45
|
+
observation?.stat === "directory" ||
|
|
46
|
+
observation?.accessibleEntries !== undefined;
|
|
47
|
+
const missingDirectory = observation?.directoryExists === false &&
|
|
48
|
+
observation.fileExists !== true &&
|
|
49
|
+
observation.stat !== "file";
|
|
50
|
+
if (directory || missingDirectory)
|
|
51
|
+
watchDirs.add(input.file);
|
|
52
|
+
if (!directory || observation?.fileExists !== undefined)
|
|
53
|
+
watchFiles.add(input.file);
|
|
54
|
+
// Failed envelopes carry no generation evidence. This rare
|
|
55
|
+
// path must still classify existing recovery directories.
|
|
56
|
+
if (input.evidence === undefined) {
|
|
57
|
+
try {
|
|
58
|
+
if (fs.statSync(input.file).isDirectory())
|
|
59
|
+
watchDirs.add(input.file);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// Missing files are already tracked through watchFiles.
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
let contents;
|
|
68
|
+
let errors;
|
|
69
|
+
try {
|
|
70
|
+
const source = await fs.promises.readFile(file, "utf8");
|
|
71
|
+
const result = await transformTtsc(file, source, options, undefined, cache, { addWatchFiles: register });
|
|
72
|
+
contents = result?.code ?? source;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
for (const input of previous.get(file)?.watchFiles ?? [])
|
|
76
|
+
watchFiles.add(input);
|
|
77
|
+
for (const input of previous.get(file)?.watchDirs ?? [])
|
|
78
|
+
watchDirs.add(input);
|
|
79
|
+
// Returning errors with dependencies lets an initially failing
|
|
80
|
+
// build observe its repair; throwing discards those channels.
|
|
81
|
+
errors = [
|
|
82
|
+
{
|
|
83
|
+
text: error instanceof Error ? error.message : String(error),
|
|
84
|
+
detail: error,
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
contents = "";
|
|
88
|
+
}
|
|
89
|
+
const dependencies = {
|
|
90
|
+
watchFiles: [...watchFiles],
|
|
91
|
+
watchDirs: [...watchDirs],
|
|
92
|
+
};
|
|
93
|
+
previous.set(file, dependencies);
|
|
94
|
+
return {
|
|
95
|
+
contents,
|
|
96
|
+
errors,
|
|
97
|
+
loader: file.endsWith(".tsx") ? "tsx" : "ts",
|
|
98
|
+
resolveDir: path.dirname(file),
|
|
99
|
+
...dependencies,
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export { createEsbuildOptions };
|
|
108
|
+
//# sourceMappingURL=esbuild.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild.mjs","sources":["../../src/core/esbuild.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAcA;AACM,SAAU,oBAAoB,CAClC,OAAoC,EACpC,QAAmC,EAAA;AAEnC,IAAA,MAAM,KAAK,GAAG,wBAAwB,EAAE;AACxC,IAAA,MAAM,MAAM,GAAG,IAAI,OAAO,EAAU;IACpC,IAAI,UAAU,GAAG,CAAC;IAClB,OAAO;AACL,QAAA,IAAI,EAAE,eAAe;AACrB,QAAA,OAAO,EAAE;AACP,YAAA,KAAK,CAAC,KAAK,EAAA;;;AAGT,gBAAA,KAAK,CAAC,OAAO,CAAC,MAAK;oBACjB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;AACtB,wBAAA,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC;wBACjB,UAAU,IAAI,CAAC;oBACjB;oBACA,uBAAuB,CAAC,KAAK,CAAC;AAChC,gBAAA,CAAC,CAAC;AACF,gBAAA,KAAK,CAAC,SAAS,CAAC,MAAK;AACnB,oBAAA,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;wBAAE;oBAC3B,UAAU,IAAI,CAAC;oBACf,IAAI,UAAU,KAAK,CAAC;wBAAE,uBAAuB,CAAC,KAAK,CAAC;AACtD,gBAAA,CAAC,CAAC;AACF,gBAAA,MAAM,QAAQ,GAAG,IAAI,GAAG,EAGrB;;;gBAGH,KAAK,CAAC,MAAM,CACV,EAAE,MAAM,EAAE,gCAAgC,EAAE,SAAS,EAAE,MAAM,EAAE,EAC/D,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAI;AACvB,oBAAA,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;wBAAE;oBACrB,MAAM,UAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,CAAC;AAC1C,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;;;"}
|
package/lib/core/index.js
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var fs = require('node:fs');
|
|
6
|
-
var path = require('node:path');
|
|
7
5
|
var unplugin$1 = require('unplugin');
|
|
6
|
+
var esbuild = require('./esbuild.js');
|
|
8
7
|
var options = require('./options.js');
|
|
9
8
|
var sourceExtensions = require('./sourceExtensions.js');
|
|
10
9
|
var transform = require('./transform.js');
|
|
@@ -44,10 +43,13 @@ const virtualModulePattern = /\0/;
|
|
|
44
43
|
* server configured without a watcher takes the pass lifecycle with them,
|
|
45
44
|
* having declared it will observe no edit at all.
|
|
46
45
|
*/
|
|
47
|
-
const unpluginFactory = (rawOptions = {}) => {
|
|
46
|
+
const unpluginFactory = (rawOptions = {}, meta) => {
|
|
48
47
|
const options$1 = options.resolveOptions(rawOptions);
|
|
48
|
+
if (meta.framework === "esbuild") {
|
|
49
|
+
return esbuild.createEsbuildOptions(options$1, isTransformTarget);
|
|
50
|
+
}
|
|
49
51
|
const transformCache = transform.createTtscTransformCache();
|
|
50
|
-
const
|
|
52
|
+
const serveInputs = viteServe.createViteServeInputWatch();
|
|
51
53
|
let aliases;
|
|
52
54
|
let viteCommand;
|
|
53
55
|
let viteWatching = true;
|
|
@@ -62,13 +64,6 @@ const unpluginFactory = (rawOptions = {}) => {
|
|
|
62
64
|
// old containers cannot dispose a replacement's freshly initialized cache.
|
|
63
65
|
let viteBuildOwners = new WeakSet();
|
|
64
66
|
let viteBuildLifecycles = 0;
|
|
65
|
-
// esbuild schedules one-shot onDispose callbacks after it settles the build
|
|
66
|
-
// Promise. Acquire ownership only at onStart: plugin setup runs before build
|
|
67
|
-
// option validation, and a validation failure has no onDispose callback with
|
|
68
|
-
// which to release a setup-time owner. Once a build has actually started, the
|
|
69
|
-
// count keeps an older delayed callback from disposing its active generation.
|
|
70
|
-
const esbuildOwners = new WeakSet();
|
|
71
|
-
let esbuildLifecycles = 0;
|
|
72
67
|
return {
|
|
73
68
|
name,
|
|
74
69
|
enforce: "pre",
|
|
@@ -98,14 +93,11 @@ const unpluginFactory = (rawOptions = {}) => {
|
|
|
98
93
|
viteBuildWatching =
|
|
99
94
|
config.build?.watch != null;
|
|
100
95
|
},
|
|
101
|
-
//
|
|
102
|
-
//
|
|
103
|
-
//
|
|
104
|
-
// hook can route watch inputs that do not exist yet — superseding
|
|
105
|
-
// resolution candidates above all — around that graph and still
|
|
106
|
-
// invalidate their importers when the path is created.
|
|
96
|
+
// Compiler dependencies belong to the filesystem watch graph. Vite's
|
|
97
|
+
// transform-context addWatchFile also inserts runtime imports, so none
|
|
98
|
+
// of those dependencies may use that channel during serve (#1368).
|
|
107
99
|
configureServer(server) {
|
|
108
|
-
|
|
100
|
+
serveInputs.attach(server);
|
|
109
101
|
},
|
|
110
102
|
// Vite calls buildEnd when the dev server closes, and Rollup calls it at
|
|
111
103
|
// the end of every build phase; drop every poller and, once the last
|
|
@@ -122,15 +114,15 @@ const unpluginFactory = (rawOptions = {}) => {
|
|
|
122
114
|
// fixing one of the two sites alone left this host recompiling the whole
|
|
123
115
|
// project per edit (samchon/ttsc#1301). The watching build hands its
|
|
124
116
|
// teardown to `closeWatcher` below instead.
|
|
125
|
-
buildEnd() {
|
|
117
|
+
async buildEnd() {
|
|
126
118
|
if (viteBuildOwners.delete(this)) {
|
|
127
119
|
viteBuildLifecycles -= 1;
|
|
128
120
|
}
|
|
129
121
|
if (viteBuildLifecycles === 0) {
|
|
130
|
-
missingInputs.dispose();
|
|
131
122
|
if (viteCommand === "serve" || !viteBuildWatching) {
|
|
132
123
|
transform.resetTtscTransformCache(transformCache);
|
|
133
124
|
}
|
|
125
|
+
await serveInputs.dispose();
|
|
134
126
|
}
|
|
135
127
|
},
|
|
136
128
|
// The watching build's real teardown, and the only hook in a
|
|
@@ -147,11 +139,11 @@ const unpluginFactory = (rawOptions = {}) => {
|
|
|
147
139
|
// `buildEnd` would then decrement a counter that is already zero and
|
|
148
140
|
// strand it below zero, after which the disposal above could never fire
|
|
149
141
|
// again for this plugin instance.
|
|
150
|
-
closeWatcher() {
|
|
142
|
+
async closeWatcher() {
|
|
151
143
|
viteBuildOwners = new WeakSet();
|
|
152
144
|
viteBuildLifecycles = 0;
|
|
153
|
-
missingInputs.dispose();
|
|
154
145
|
transform.resetTtscTransformCache(transformCache);
|
|
146
|
+
await serveInputs.dispose();
|
|
155
147
|
},
|
|
156
148
|
},
|
|
157
149
|
// Rollup and Rolldown carry none of the Vite block's hooks, so before this
|
|
@@ -201,23 +193,14 @@ const unpluginFactory = (rawOptions = {}) => {
|
|
|
201
193
|
transform.resetTtscTransformCache(transformCache);
|
|
202
194
|
});
|
|
203
195
|
},
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
build.onDispose(() => {
|
|
213
|
-
if (!esbuildOwners.delete(build)) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
esbuildLifecycles -= 1;
|
|
217
|
-
if (esbuildLifecycles === 0) {
|
|
218
|
-
transform.resetTtscTransformCache(transformCache);
|
|
219
|
-
}
|
|
220
|
-
});
|
|
196
|
+
farm: {
|
|
197
|
+
// Farm calls buildStart only for the initial compilation. Every update
|
|
198
|
+
// opens a new pass so a failed verdict can recover, while an unchanged
|
|
199
|
+
// successful generation remains reusable across its module deliveries.
|
|
200
|
+
updateModules: {
|
|
201
|
+
executor() {
|
|
202
|
+
transform.beginTtscTransformBuild(transformCache);
|
|
203
|
+
},
|
|
221
204
|
},
|
|
222
205
|
},
|
|
223
206
|
buildStart() {
|
|
@@ -261,58 +244,35 @@ const unpluginFactory = (rawOptions = {}) => {
|
|
|
261
244
|
return undefined;
|
|
262
245
|
}
|
|
263
246
|
return transform.transformTtsc(file, source, options$1, aliases, transformCache, {
|
|
264
|
-
//
|
|
265
|
-
//
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
// missing paths and directories, so those are watched against their
|
|
272
|
-
// compiler predicates instead and invalidate this module when the
|
|
273
|
-
// observation changes.
|
|
274
|
-
addWatchFile: (watched, evidence) => {
|
|
275
|
-
if (viteCommand === "serve" && missingInputs.serving()) {
|
|
276
|
-
const observation = evidence?.state?.codec === "predicates"
|
|
277
|
-
? evidence.state.observation
|
|
278
|
-
: undefined;
|
|
279
|
-
const unsafePredicate = observation !== undefined &&
|
|
280
|
-
observation.fileExists !== true &&
|
|
281
|
-
observation.stat !== "file" &&
|
|
282
|
-
observation.readFile?.ok !== true
|
|
283
|
-
? observation
|
|
284
|
-
: undefined;
|
|
285
|
-
if (unsafePredicate !== undefined) {
|
|
286
|
-
missingInputs.watch(watched, path.resolve(file), unsafePredicate);
|
|
287
|
-
return;
|
|
247
|
+
// A watcherless server has no invalidation channel and needs no
|
|
248
|
+
// watch-input derivation. Every other host keeps its native contract.
|
|
249
|
+
addWatchFiles: viteCommand === "serve" && !viteWatching
|
|
250
|
+
? undefined
|
|
251
|
+
: (inputs, failed) => {
|
|
252
|
+
if (viteCommand === "serve") {
|
|
253
|
+
serveInputs.replace(file, inputs, failed);
|
|
288
254
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
255
|
+
else {
|
|
256
|
+
const native = this.getNativeBuildContext?.();
|
|
257
|
+
for (const input of inputs) {
|
|
258
|
+
if (native?.framework === "rspack" &&
|
|
259
|
+
native.loaderContext !== undefined) {
|
|
260
|
+
// Compilation-level dependencies schedule a pass but do
|
|
261
|
+
// not invalidate Rspack's cached transformed modules.
|
|
262
|
+
if (input.evidence?.missing === true)
|
|
263
|
+
native.loaderContext.addMissingDependency(input.file);
|
|
264
|
+
else
|
|
265
|
+
native.loaderContext.addDependency(input.file);
|
|
266
|
+
}
|
|
267
|
+
else if (native?.framework === "farm") {
|
|
268
|
+
native.context.addWatchFile(file, input.file);
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
this.addWatchFile(input.file);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
303
274
|
}
|
|
304
|
-
}
|
|
305
|
-
// A dev server configured without a watcher can never deliver a
|
|
306
|
-
// change event, so a registration here buys nothing, and it is not
|
|
307
|
-
// free: Vite's import analysis resolves every registered path like a
|
|
308
|
-
// real import of the transformed module, once per module. The
|
|
309
|
-
// adapter's own missing-input poll above stays active either way,
|
|
310
|
-
// because it never depended on Vite's watcher.
|
|
311
|
-
if (viteCommand === "serve" && !viteWatching) {
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
this.addWatchFile(watched);
|
|
315
|
-
},
|
|
275
|
+
},
|
|
316
276
|
// A module the plugin declared volatile depends on non-file inputs,
|
|
317
277
|
// which no file-dependency snapshot can represent; mark it
|
|
318
278
|
// uncacheable where the bundler exposes that control.
|
package/lib/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/core/index.ts"],"sourcesContent":[null],"names":["typescriptTransformSourcePattern","options","resolveOptions","createTtscTransformCache","
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/core/index.ts"],"sourcesContent":[null],"names":["typescriptTransformSourcePattern","options","resolveOptions","createEsbuildOptions","createTtscTransformCache","createViteServeInputWatch","resetTtscTransformCache","beginTtscTransformBuild","stripQuery","transformTtsc","createUnplugin","isDeclarationFile"],"mappings":";;;;;;;;;;;;;AAyBA,MAAM,IAAI,GAAG,eAAe;AAC5B;;;;;;;;AAQG;AACI,MAAM,iBAAiB,GAAGA;AACjC;AACA,MAAM,kBAAkB,GAAG,oCAAoC;AAC/D;;;AAGG;AACH,MAAM,oBAAoB,GAAG,IAAI;AAEjC;;;;;;;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