@ttsc/unplugin 0.20.0 → 0.21.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.
@@ -0,0 +1,74 @@
1
+ /** One module node inside a Vite module graph; opaque to this module. */
2
+ type ViteModuleNodeLike = object;
3
+ /**
4
+ * The module-graph surface this module touches, shared by Vite's mixed module
5
+ * graph and the per-environment graphs of the environment API.
6
+ */
7
+ interface ViteModuleGraphLike {
8
+ fileToModulesMap?: Map<string, Set<ViteModuleNodeLike>>;
9
+ getModulesByFile?(file: string): Set<ViteModuleNodeLike> | undefined;
10
+ invalidateModule?(node: ViteModuleNodeLike): void;
11
+ }
12
+ /** A channel that can deliver a full-reload event to connected clients. */
13
+ interface ViteHotChannelLike {
14
+ send?(payload: {
15
+ path?: string;
16
+ type: "full-reload";
17
+ }): void;
18
+ }
19
+ /** One dev-server environment (client, ssr, or a custom one). */
20
+ interface ViteEnvironmentLike {
21
+ hot?: ViteHotChannelLike;
22
+ moduleGraph?: ViteModuleGraphLike;
23
+ }
24
+ /**
25
+ * Minimal structural view of the Vite dev server. Declared locally instead of
26
+ * importing `vite` so the published type declarations never require Vite to be
27
+ * installed, and so one shape spans the mixed module graph (Vite 5), the
28
+ * environment API (Vite 6+), and whichever of `ws`/`hot` a major still
29
+ * carries.
30
+ */
31
+ export interface ViteDevServerLike {
32
+ environments?: Record<string, ViteEnvironmentLike>;
33
+ hot?: ViteHotChannelLike;
34
+ moduleGraph?: ViteModuleGraphLike;
35
+ ws?: ViteHotChannelLike;
36
+ }
37
+ /**
38
+ * Filesystem watch for derived watch inputs that do not exist while a Vite dev
39
+ * server is running.
40
+ *
41
+ * Vite serve treats every transform-context `addWatchFile()` registration as an
42
+ * added import: `TransformPluginContext.addWatchFile` stores the path in
43
+ * `_addedImports`, and `vite:import-analysis` resolves each entry like a real
44
+ * import of the transformed module. A missing path — a superseding resolution
45
+ * candidate or a plugin-reported dependency that is not generated yet — then
46
+ * fails that resolve and turns the importer's first request into a 500, even
47
+ * though the transform itself succeeded.
48
+ *
49
+ * This registry is the serve-only replacement for those registrations. Each
50
+ * missing path is stat-polled; when it is created, every importer that
51
+ * registered it is invalidated in the server's module graphs and one
52
+ * full-reload is sent, so the next request retransforms the importer against
53
+ * the new resolution winner. The project transform cache re-validates through
54
+ * its external-input hashes (a recorded `missing` marker differs from a content
55
+ * hash), so the retransform recompiles instead of replaying.
56
+ */
57
+ export interface ViteServeMissingInputWatch {
58
+ /** Adopt the dev server whose module graphs creation events invalidate. */
59
+ attach(server: ViteDevServerLike): void;
60
+ /** Stop every poll; safe to call repeatedly. */
61
+ dispose(): void;
62
+ /**
63
+ * Report whether a dev server has ever been attached. This is not a liveness
64
+ * predicate — the reference intentionally survives the server's close (see
65
+ * {@link dispose}) — so route decisions must also gate on the resolved
66
+ * config's `command`, as the adapter does.
67
+ */
68
+ serving(): boolean;
69
+ /** Register one missing watch input derived for `importer`. */
70
+ watch(input: string, importer: string): void;
71
+ }
72
+ /** Create an empty missing-input watch for one plugin instance. */
73
+ export declare function createViteServeMissingInputWatch(): ViteServeMissingInputWatch;
74
+ export {};
@@ -0,0 +1,180 @@
1
+ 'use strict';
2
+
3
+ var fs = require('node:fs');
4
+ var path = require('node:path');
5
+ var transform = require('./transform.js');
6
+
7
+ /**
8
+ * How often each registered missing watch input is stat-polled, in
9
+ * milliseconds.
10
+ *
11
+ * Polling is the only watch primitive that covers the whole class: the dev
12
+ * server's chokidar watcher ignores every `node_modules` directory, which is
13
+ * exactly where superseding resolution candidates usually live, and `fs.watch`
14
+ * cannot observe a path whose parent directories do not exist yet. One `stat`
15
+ * every half second per missing path is negligible against a dev server's
16
+ * baseline.
17
+ */
18
+ const MISSING_INPUT_POLL_INTERVAL = 500;
19
+ /** Create an empty missing-input watch for one plugin instance. */
20
+ function createViteServeMissingInputWatch() {
21
+ const entries = new Map();
22
+ let server;
23
+ const unwatch = (identity, entry) => {
24
+ fs.unwatchFile(entry.spelling, entry.listener);
25
+ entries.delete(identity);
26
+ };
27
+ return {
28
+ attach(next) {
29
+ server = next;
30
+ },
31
+ dispose() {
32
+ for (const [identity, entry] of entries) {
33
+ unwatch(identity, entry);
34
+ }
35
+ // The server reference deliberately survives: `vite.restartServer`
36
+ // configures the replacement server (attach) before it closes the old
37
+ // one (whose buildEnd runs this dispose), so unsetting it here would
38
+ // detach the freshly attached replacement and revive the 500 this
39
+ // module exists to prevent. A same-instance `vite build` after a serve
40
+ // is instead excluded by the adapter's `config.command` gate.
41
+ },
42
+ serving() {
43
+ return server !== undefined;
44
+ },
45
+ watch(input, importer) {
46
+ const spelling = path.resolve(input);
47
+ const identity = transform.pathIdentityKey(spelling);
48
+ const existing = entries.get(identity);
49
+ if (existing !== undefined) {
50
+ existing.importers.add(path.resolve(importer));
51
+ return;
52
+ }
53
+ const entry = {
54
+ importers: new Set([path.resolve(importer)]),
55
+ listener: (current) => {
56
+ // `fs.watchFile` reports a missing path as zeroed stats (and fires
57
+ // once with them right after registration); only a poll that
58
+ // observes a real file is a creation event.
59
+ if (current.mtimeMs === 0 && !fs.existsSync(entry.spelling)) {
60
+ return;
61
+ }
62
+ unwatch(identity, entry);
63
+ if (server === undefined) {
64
+ return;
65
+ }
66
+ invalidateImporters(server, entry.importers);
67
+ sendFullReload(server);
68
+ },
69
+ spelling,
70
+ };
71
+ entries.set(identity, entry);
72
+ const watcher = fs.watchFile(spelling, { interval: MISSING_INPUT_POLL_INTERVAL }, entry.listener);
73
+ // A poller must never keep the dev-server process alive on its own.
74
+ watcher.unref?.();
75
+ // `fs.watchFile` snapshots the path's stats at registration and fires
76
+ // only on a subsequent change, so a file created between the adapter's
77
+ // existence check and this registration would count as "unchanged" and
78
+ // never fire. One deferred recheck closes that window; routing through
79
+ // the listener keeps a single finalization path.
80
+ const recheck = setTimeout(() => {
81
+ if (entries.get(identity) !== entry) {
82
+ return;
83
+ }
84
+ try {
85
+ entry.listener(fs.statSync(entry.spelling));
86
+ }
87
+ catch {
88
+ // Still missing (or deleted again): the ordinary poll stays armed.
89
+ }
90
+ }, MISSING_INPUT_POLL_INTERVAL);
91
+ recheck.unref?.();
92
+ },
93
+ };
94
+ }
95
+ /**
96
+ * Invalidate every module-graph node of the registered importers so the next
97
+ * request retransforms them. Importers keep their original absolute spelling so
98
+ * the module graph's exact-key lookup can hit; graph lookups still go through
99
+ * {@link selectModulesByFile} because module-graph file keys are
100
+ * slash-normalized and, on case-insensitive filesystems, may not match the
101
+ * compiler's spelling byte for byte.
102
+ */
103
+ function invalidateImporters(server, importers) {
104
+ for (const graph of selectModuleGraphs(server)) {
105
+ for (const importer of importers) {
106
+ for (const node of selectModulesByFile(graph, importer)) {
107
+ try {
108
+ graph.invalidateModule?.(node);
109
+ }
110
+ catch {
111
+ // A graph shape this structural view mispredicts must not crash the
112
+ // poll; the full-reload below still forces a refetch, and the
113
+ // transform cache's external-input hashes force the recompile.
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }
119
+ /**
120
+ * Enumerate the server's module graphs: one per environment under the
121
+ * environment API (Vite 6+), otherwise the mixed module graph (Vite 5).
122
+ */
123
+ function selectModuleGraphs(server) {
124
+ const graphs = [];
125
+ for (const environment of Object.values(server.environments ?? {})) {
126
+ if (environment?.moduleGraph !== undefined) {
127
+ graphs.push(environment.moduleGraph);
128
+ }
129
+ }
130
+ if (graphs.length === 0 && server.moduleGraph !== undefined) {
131
+ graphs.push(server.moduleGraph);
132
+ }
133
+ return graphs;
134
+ }
135
+ /**
136
+ * Look up the module nodes registered for one importer spelling: the fast
137
+ * slash-normalized `getModulesByFile` lookup first, then an identity scan of
138
+ * `fileToModulesMap` for spellings that differ only by separator or case.
139
+ */
140
+ function selectModulesByFile(graph, importer) {
141
+ const direct = graph.getModulesByFile?.(importer.replace(/\\/g, "/"));
142
+ if (direct !== undefined && direct.size !== 0) {
143
+ return [...direct];
144
+ }
145
+ const identity = transform.pathIdentityKey(importer);
146
+ const output = [];
147
+ for (const [file, nodes] of graph.fileToModulesMap ?? []) {
148
+ if (typeof file === "string" && transform.pathIdentityKey(file) === identity) {
149
+ output.push(...nodes);
150
+ }
151
+ }
152
+ return output;
153
+ }
154
+ /**
155
+ * Deliver one full-reload so connected clients refetch the invalidated
156
+ * importers. The channels differ across Vite majors (`ws`, deprecated `hot`,
157
+ * per-environment `hot`); the first one that accepts the payload wins.
158
+ */
159
+ function sendFullReload(server) {
160
+ for (const channel of [
161
+ server.ws,
162
+ server.hot,
163
+ server.environments?.client?.hot,
164
+ ]) {
165
+ if (channel?.send === undefined) {
166
+ continue;
167
+ }
168
+ try {
169
+ channel.send({ path: "*", type: "full-reload" });
170
+ return;
171
+ }
172
+ catch {
173
+ // Try the next channel; an unsupported payload on one major must not
174
+ // suppress delivery through another.
175
+ }
176
+ }
177
+ }
178
+
179
+ exports.createViteServeMissingInputWatch = createViteServeMissingInputWatch;
180
+ //# sourceMappingURL=viteServe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viteServe.js","sources":["../../src/core/viteServe.ts"],"sourcesContent":[null],"names":["pathIdentityKey"],"mappings":";;;;;;AAKA;;;;;;;;;;AAUG;AACH,MAAM,2BAA2B,GAAG,GAAG;AAmFvC;SACgB,gCAAgC,GAAA;AAC9C,IAAA,MAAM,OAAO,GAAG,IAAI,GAAG,EAA8B;AACrD,IAAA,IAAI,MAAqC;AAEzC,IAAA,MAAM,OAAO,GAAG,CAAC,QAAgB,EAAE,KAAyB,KAAU;QACpE,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC;AAC9C,QAAA,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC;AAC1B,IAAA,CAAC;IAED,OAAO;AACL,QAAA,MAAM,CAAC,IAAI,EAAA;YACT,MAAM,GAAG,IAAI;QACf,CAAC;QACD,OAAO,GAAA;YACL,KAAK,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE;AACvC,gBAAA,OAAO,CAAC,QAAQ,EAAE,K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IdentityKey } from './transform.mjs';
4
+
5
+ /**
6
+ * How often each registered missing watch input is stat-polled, in
7
+ * milliseconds.
8
+ *
9
+ * Polling is the only watch primitive that covers the whole class: the dev
10
+ * server's chokidar watcher ignores every `node_modules` directory, which is
11
+ * exactly where superseding resolution candidates usually live, and `fs.watch`
12
+ * cannot observe a path whose parent directories do not exist yet. One `stat`
13
+ * every half second per missing path is negligible against a dev server's
14
+ * baseline.
15
+ */
16
+ const MISSING_INPUT_POLL_INTERVAL = 500;
17
+ /** Create an empty missing-input watch for one plugin instance. */
18
+ function createViteServeMissingInputWatch() {
19
+ const entries = new Map();
20
+ let server;
21
+ const unwatch = (identity, entry) => {
22
+ fs.unwatchFile(entry.spelling, entry.listener);
23
+ entries.delete(identity);
24
+ };
25
+ return {
26
+ attach(next) {
27
+ server = next;
28
+ },
29
+ dispose() {
30
+ for (const [identity, entry] of entries) {
31
+ unwatch(identity, entry);
32
+ }
33
+ // The server reference deliberately survives: `vite.restartServer`
34
+ // configures the replacement server (attach) before it closes the old
35
+ // one (whose buildEnd runs this dispose), so unsetting it here would
36
+ // detach the freshly attached replacement and revive the 500 this
37
+ // module exists to prevent. A same-instance `vite build` after a serve
38
+ // is instead excluded by the adapter's `config.command` gate.
39
+ },
40
+ serving() {
41
+ return server !== undefined;
42
+ },
43
+ watch(input, importer) {
44
+ const spelling = path.resolve(input);
45
+ const identity = pathIdentityKey(spelling);
46
+ const existing = entries.get(identity);
47
+ if (existing !== undefined) {
48
+ existing.importers.add(path.resolve(importer));
49
+ return;
50
+ }
51
+ const entry = {
52
+ importers: new Set([path.resolve(importer)]),
53
+ listener: (current) => {
54
+ // `fs.watchFile` reports a missing path as zeroed stats (and fires
55
+ // once with them right after registration); only a poll that
56
+ // observes a real file is a creation event.
57
+ if (current.mtimeMs === 0 && !fs.existsSync(entry.spelling)) {
58
+ return;
59
+ }
60
+ unwatch(identity, entry);
61
+ if (server === undefined) {
62
+ return;
63
+ }
64
+ invalidateImporters(server, entry.importers);
65
+ sendFullReload(server);
66
+ },
67
+ spelling,
68
+ };
69
+ entries.set(identity, entry);
70
+ const watcher = fs.watchFile(spelling, { interval: MISSING_INPUT_POLL_INTERVAL }, entry.listener);
71
+ // A poller must never keep the dev-server process alive on its own.
72
+ watcher.unref?.();
73
+ // `fs.watchFile` snapshots the path's stats at registration and fires
74
+ // only on a subsequent change, so a file created between the adapter's
75
+ // existence check and this registration would count as "unchanged" and
76
+ // never fire. One deferred recheck closes that window; routing through
77
+ // the listener keeps a single finalization path.
78
+ const recheck = setTimeout(() => {
79
+ if (entries.get(identity) !== entry) {
80
+ return;
81
+ }
82
+ try {
83
+ entry.listener(fs.statSync(entry.spelling));
84
+ }
85
+ catch {
86
+ // Still missing (or deleted again): the ordinary poll stays armed.
87
+ }
88
+ }, MISSING_INPUT_POLL_INTERVAL);
89
+ recheck.unref?.();
90
+ },
91
+ };
92
+ }
93
+ /**
94
+ * Invalidate every module-graph node of the registered importers so the next
95
+ * request retransforms them. Importers keep their original absolute spelling so
96
+ * the module graph's exact-key lookup can hit; graph lookups still go through
97
+ * {@link selectModulesByFile} because module-graph file keys are
98
+ * slash-normalized and, on case-insensitive filesystems, may not match the
99
+ * compiler's spelling byte for byte.
100
+ */
101
+ function invalidateImporters(server, importers) {
102
+ for (const graph of selectModuleGraphs(server)) {
103
+ for (const importer of importers) {
104
+ for (const node of selectModulesByFile(graph, importer)) {
105
+ try {
106
+ graph.invalidateModule?.(node);
107
+ }
108
+ catch {
109
+ // A graph shape this structural view mispredicts must not crash the
110
+ // poll; the full-reload below still forces a refetch, and the
111
+ // transform cache's external-input hashes force the recompile.
112
+ }
113
+ }
114
+ }
115
+ }
116
+ }
117
+ /**
118
+ * Enumerate the server's module graphs: one per environment under the
119
+ * environment API (Vite 6+), otherwise the mixed module graph (Vite 5).
120
+ */
121
+ function selectModuleGraphs(server) {
122
+ const graphs = [];
123
+ for (const environment of Object.values(server.environments ?? {})) {
124
+ if (environment?.moduleGraph !== undefined) {
125
+ graphs.push(environment.moduleGraph);
126
+ }
127
+ }
128
+ if (graphs.length === 0 && server.moduleGraph !== undefined) {
129
+ graphs.push(server.moduleGraph);
130
+ }
131
+ return graphs;
132
+ }
133
+ /**
134
+ * Look up the module nodes registered for one importer spelling: the fast
135
+ * slash-normalized `getModulesByFile` lookup first, then an identity scan of
136
+ * `fileToModulesMap` for spellings that differ only by separator or case.
137
+ */
138
+ function selectModulesByFile(graph, importer) {
139
+ const direct = graph.getModulesByFile?.(importer.replace(/\\/g, "/"));
140
+ if (direct !== undefined && direct.size !== 0) {
141
+ return [...direct];
142
+ }
143
+ const identity = pathIdentityKey(importer);
144
+ const output = [];
145
+ for (const [file, nodes] of graph.fileToModulesMap ?? []) {
146
+ if (typeof file === "string" && pathIdentityKey(file) === identity) {
147
+ output.push(...nodes);
148
+ }
149
+ }
150
+ return output;
151
+ }
152
+ /**
153
+ * Deliver one full-reload so connected clients refetch the invalidated
154
+ * importers. The channels differ across Vite majors (`ws`, deprecated `hot`,
155
+ * per-environment `hot`); the first one that accepts the payload wins.
156
+ */
157
+ function sendFullReload(server) {
158
+ for (const channel of [
159
+ server.ws,
160
+ server.hot,
161
+ server.environments?.client?.hot,
162
+ ]) {
163
+ if (channel?.send === undefined) {
164
+ continue;
165
+ }
166
+ try {
167
+ channel.send({ path: "*", type: "full-reload" });
168
+ return;
169
+ }
170
+ catch {
171
+ // Try the next channel; an unsupported payload on one major must not
172
+ // suppress delivery through another.
173
+ }
174
+ }
175
+ }
176
+
177
+ export { createViteServeMissingInputWatch };
178
+ //# sourceMappingURL=viteServe.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viteServe.mjs","sources":["../../src/core/viteServe.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAKA;;;;;;;;;;AAUG;AACH,MAAM,2BAA2B,GAAG,GAAG;AAmFvC;SACgB,gCAAgC,GAAA;AAC9C,IAAA,MAAM,OAAO,GAAG,IAAI,GAAG,EAA8B;AACrD,IAAA,IAAI,MAAq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AM,CAAC,EAAE;AACT,QAAA,MAAM,CAAC,GAAG;AACV,QAAA,MAAM,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG;AACjC,KAAA,EAAE;AACD,QAAA,IAAI,OAAO,EAAE,IAAI,KAAK,SAAS,EAAE;YAC/B;QACF;AACA,QAAA,IAAI;AACF,YAAA,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;YAChD;QACF;AAAE,QAAA,MAAM;;;QAGR;IACF;AACF;;;;"}
package/lib/turbopack.js CHANGED
@@ -10,9 +10,9 @@ const nodeModulesPattern = /(?:^|[/\\])node_modules(?:[/\\]|$)/;
10
10
  /**
11
11
  * Per-process transform cache. Turbopack runs loaders in a worker pool and
12
12
  * never signals build boundaries to a loader, so the cache lives for the
13
- * worker's lifetime; entries self-invalidate by re-hashing the project's input
14
- * files on every request (see `transformTtsc`), which is the same freshness
15
- * rule the bundler-plugin adapters rely on between watch rebuilds.
13
+ * worker's lifetime. Because no build-start boundary exists, every cache hit
14
+ * validates all project and graph inputs before selecting output (see
15
+ * `transformTtsc`).
16
16
  */
17
17
  const transformCache = transform.createTtscTransformCache();
18
18
  /**
package/lib/turbopack.mjs CHANGED
@@ -6,9 +6,9 @@ const nodeModulesPattern = /(?:^|[/\\])node_modules(?:[/\\]|$)/;
6
6
  /**
7
7
  * Per-process transform cache. Turbopack runs loaders in a worker pool and
8
8
  * never signals build boundaries to a loader, so the cache lives for the
9
- * worker's lifetime; entries self-invalidate by re-hashing the project's input
10
- * files on every request (see `transformTtsc`), which is the same freshness
11
- * rule the bundler-plugin adapters rely on between watch rebuilds.
9
+ * worker's lifetime. Because no build-start boundary exists, every cache hit
10
+ * validates all project and graph inputs before selecting output (see
11
+ * `transformTtsc`).
12
12
  */
13
13
  const transformCache = createTtscTransformCache();
14
14
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttsc/unplugin",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "description": "Bundler adapters for ttsc plugins.",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.mjs",
@@ -95,7 +95,7 @@
95
95
  "unplugin": "^2.3.11"
96
96
  },
97
97
  "peerDependencies": {
98
- "ttsc": "^0.20.0"
98
+ "ttsc": "^0.21.0"
99
99
  },
100
100
  "devDependencies": {
101
101
  "@rollup/plugin-commonjs": "^29.0.2",
@@ -108,7 +108,7 @@
108
108
  "tslib": "^2.8.1",
109
109
  "typescript": "^7.0.2",
110
110
  "vite": "^7.1.12",
111
- "ttsc": "0.20.0"
111
+ "ttsc": "0.21.0"
112
112
  },
113
113
  "repository": {
114
114
  "type": "git",