@workday/canvas-kit-styling-transform 15.0.16 → 15.0.18

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.
@@ -1,6 +1,8 @@
1
1
  import ts from 'typescript';
2
2
  /** Get the contents of the tsconfig in the system */
3
3
  export declare function getTSConfigFile(tsconfigPath: string): ts.ParsedCommandLine;
4
+ /** Create a one-shot TypeScript program suitable for production builds. */
5
+ export declare const createProgram: (tsconfigPath: string, compilerOptions: ts.CompilerOptions) => ts.Program;
4
6
  export declare const getCompilerOptions: (tsconfigPath: string) => ts.CompilerOptions;
5
7
  /**
6
8
  * Create a watch program for TypeScript with transformers. It watches the specified
@@ -1 +1 @@
1
- {"version":3,"file":"createTypeScriptWatchProgram.d.ts","sourceRoot":"","sources":["../../../lib/createTypeScriptWatchProgram.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,qDAAqD;AACrD,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,wBAKnD;AAED,eAAO,MAAM,kBAAkB,iBAAkB,MAAM,uBAWtD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,oBACJ,GAAG,eAAe,gBACrB,MAAM,uCACiB,GAAG,cAAc,KAAK,IAAI,KAC9D,CAAC,GAAG,cAAc,EAAE,MAAM,IAAI,CAehC,CAAC"}
1
+ {"version":3,"file":"createTypeScriptWatchProgram.d.ts","sourceRoot":"","sources":["../../../lib/createTypeScriptWatchProgram.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,qDAAqD;AACrD,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,wBAKnD;AAED,2EAA2E;AAC3E,eAAO,MAAM,aAAa,iBACV,MAAM,mBACH,GAAG,eAAe,KAClC,GAAG,OAGL,CAAC;AAEF,eAAO,MAAM,kBAAkB,iBAAkB,MAAM,uBAWtD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,oBACJ,GAAG,eAAe,gBACrB,MAAM,uCACiB,GAAG,cAAc,KAAK,IAAI,KAC9D,CAAC,GAAG,cAAc,EAAE,MAAM,IAAI,CAehC,CAAC"}
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.startWatch = exports.getCompilerOptions = exports.getTSConfigFile = void 0;
6
+ exports.startWatch = exports.getCompilerOptions = exports.createProgram = exports.getTSConfigFile = void 0;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
8
  const typescript_1 = __importDefault(require("typescript"));
9
9
  /** Get the contents of the tsconfig in the system */
@@ -13,6 +13,12 @@ function getTSConfigFile(tsconfigPath) {
13
13
  return typescript_1.default.parseJsonConfigFileContent(configFile.config, typescript_1.default.sys, basePath, {}, tsconfigPath);
14
14
  }
15
15
  exports.getTSConfigFile = getTSConfigFile;
16
+ /** Create a one-shot TypeScript program suitable for production builds. */
17
+ const createProgram = (tsconfigPath, compilerOptions) => {
18
+ const { fileNames } = getTSConfigFile(tsconfigPath);
19
+ return typescript_1.default.createProgram(fileNames, compilerOptions);
20
+ };
21
+ exports.createProgram = createProgram;
16
22
  const getCompilerOptions = (tsconfigPath) => {
17
23
  let compilerOptions = {
18
24
  jsx: typescript_1.default.JsxEmit.React,
@@ -1 +1 @@
1
- {"version":3,"file":"vitePlugin.d.ts","sourceRoot":"","sources":["../../../lib/vitePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAC,KAAK,eAAe,EAAE,KAAK,OAAO,EAAC,MAAM,YAAY,CAAC;AAClE,OAAO,EAAC,KAAK,MAAM,EAAe,MAAM,MAAM,CAAC;AAQ/C,MAAM,WAAW,OAAO;IACtB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAChD,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAChD;;;QAGI;IACJ,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8EAA8E;IAC9E,eAAe,CAAC,EAAE,eAAe,CAAC;IAElC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC;IAE5F;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;CAClE;AAED,wBAAgB,oCAAoC,CAAC,MAAM,GAAE,OAAY,GAAG,MAAM,CA4DjF"}
1
+ {"version":3,"file":"vitePlugin.d.ts","sourceRoot":"","sources":["../../../lib/vitePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAC,KAAK,eAAe,EAAE,KAAK,OAAO,EAAC,MAAM,YAAY,CAAC;AAClE,OAAO,EAAC,KAAK,MAAM,EAAe,MAAM,MAAM,CAAC;AAQ/C,MAAM,WAAW,OAAO;IACtB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAChD,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAChD;;;QAGI;IACJ,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8EAA8E;IAC9E,eAAe,CAAC,EAAE,eAAe,CAAC;IAElC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC;IAE5F;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;CAClE;AAED,wBAAgB,oCAAoC,CAAC,MAAM,GAAE,OAAY,GAAG,MAAM,CA8EjF"}
@@ -12,17 +12,30 @@ function vitePluginTypescriptWithTransformers(config = {}) {
12
12
  let compilerOptions;
13
13
  let filter;
14
14
  const moduleInvalidationQueue = new Map();
15
+ // When the production (static) build runs, closeWatch is a no-op because there's no watch to close.
15
16
  let closeWatch;
17
+ // When the program is running in development with watch mode, tsProgram is a BuilderProgram.
18
+ // When the program is running in production, tsProgram is a Program.
19
+ // We need to get the Program from the BuilderProgram to get the correct source files.
20
+ const getProgram = () => ('getProgram' in tsProgram ? tsProgram.getProgram() : tsProgram);
16
21
  return {
17
22
  name: 'vite-plugin-typescript',
18
23
  enforce: 'pre',
19
- async configResolved() {
24
+ async configResolved(resolvedConfig) {
20
25
  var _a, _b, _c, _d;
21
26
  const tsconfigPath = (_a = config.tsconfigPath) !== null && _a !== void 0 ? _a : './tsconfig.json';
22
27
  compilerOptions = (_b = config.compilerOptions) !== null && _b !== void 0 ? _b : (await (0, createTypeScriptWatchProgram_1.getCompilerOptions)(tsconfigPath));
23
28
  const includeArray = (_c = config.include) !== null && _c !== void 0 ? _c : ['**/**.tsx?'];
24
29
  const excludeArray = (_d = config.exclude) !== null && _d !== void 0 ? _d : [];
25
30
  filter = (0, vite_1.createFilter)(includeArray, excludeArray);
31
+ // If Vite is running a production (static) build, we need to create a new Program instead of running watch mode.
32
+ if (resolvedConfig.command === 'build') {
33
+ // Watch mode keeps the Node process alive after Vite finishes.
34
+ // Storybook's static build does not reliably call closeBundle before file writes.
35
+ tsProgram = (0, createTypeScriptWatchProgram_1.createProgram)(tsconfigPath, compilerOptions);
36
+ return;
37
+ }
38
+ // Watch mode is now only used for development builds.
26
39
  [tsProgram, closeWatch] = await (0, createTypeScriptWatchProgram_1.startWatch)(compilerOptions, tsconfigPath, program => {
27
40
  tsProgram = program;
28
41
  for (const [filepath, invalidateModule] of moduleInvalidationQueue.entries()) {
@@ -37,9 +50,9 @@ function vitePluginTypescriptWithTransformers(config = {}) {
37
50
  return;
38
51
  }
39
52
  const printer = typescript_1.default.createPrinter(compilerOptions);
40
- const transformers = ((_a = config.transformers) === null || _a === void 0 ? void 0 : _a.filter(t => t !== undefined).map(t => t(tsProgram.getProgram()))) ||
41
- [];
42
- const sourceFile = tsProgram.getSourceFile(id) || typescript_1.default.createSourceFile(id, '', typescript_1.default.ScriptTarget.ES2019);
53
+ const program = getProgram();
54
+ const transformers = ((_a = config.transformers) === null || _a === void 0 ? void 0 : _a.filter(t => t !== undefined).map(t => t(program))) || [];
55
+ const sourceFile = program.getSourceFile(id) || typescript_1.default.createSourceFile(id, '', typescript_1.default.ScriptTarget.ES2019);
43
56
  const transformed = printer.printFile(typescript_1.default
44
57
  .transform(sourceFile, transformers, compilerOptions)
45
58
  .transformed.find(s => s.fileName === id) || sourceFile);
@@ -48,8 +61,13 @@ function vitePluginTypescriptWithTransformers(config = {}) {
48
61
  : transformed;
49
62
  return postTransform || transformed;
50
63
  },
64
+ // Runs when the build finishes.
65
+ // This is an extra precaution in case Storybook / Vite don't call closeBundle before the process exits.
66
+ buildEnd() {
67
+ closeWatch === null || closeWatch === void 0 ? void 0 : closeWatch();
68
+ },
51
69
  closeBundle() {
52
- closeWatch();
70
+ closeWatch === null || closeWatch === void 0 ? void 0 : closeWatch();
53
71
  },
54
72
  };
55
73
  }
@@ -1,6 +1,8 @@
1
1
  import ts from 'typescript';
2
2
  /** Get the contents of the tsconfig in the system */
3
3
  export declare function getTSConfigFile(tsconfigPath: string): ts.ParsedCommandLine;
4
+ /** Create a one-shot TypeScript program suitable for production builds. */
5
+ export declare const createProgram: (tsconfigPath: string, compilerOptions: ts.CompilerOptions) => ts.Program;
4
6
  export declare const getCompilerOptions: (tsconfigPath: string) => ts.CompilerOptions;
5
7
  /**
6
8
  * Create a watch program for TypeScript with transformers. It watches the specified
@@ -1 +1 @@
1
- {"version":3,"file":"createTypeScriptWatchProgram.d.ts","sourceRoot":"","sources":["../../../lib/createTypeScriptWatchProgram.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,qDAAqD;AACrD,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,wBAKnD;AAED,eAAO,MAAM,kBAAkB,iBAAkB,MAAM,uBAWtD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,oBACJ,GAAG,eAAe,gBACrB,MAAM,uCACiB,GAAG,cAAc,KAAK,IAAI,KAC9D,CAAC,GAAG,cAAc,EAAE,MAAM,IAAI,CAehC,CAAC"}
1
+ {"version":3,"file":"createTypeScriptWatchProgram.d.ts","sourceRoot":"","sources":["../../../lib/createTypeScriptWatchProgram.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,qDAAqD;AACrD,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,wBAKnD;AAED,2EAA2E;AAC3E,eAAO,MAAM,aAAa,iBACV,MAAM,mBACH,GAAG,eAAe,KAClC,GAAG,OAGL,CAAC;AAEF,eAAO,MAAM,kBAAkB,iBAAkB,MAAM,uBAWtD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,oBACJ,GAAG,eAAe,gBACrB,MAAM,uCACiB,GAAG,cAAc,KAAK,IAAI,KAC9D,CAAC,GAAG,cAAc,EAAE,MAAM,IAAI,CAehC,CAAC"}
@@ -6,6 +6,11 @@ export function getTSConfigFile(tsconfigPath) {
6
6
  const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
7
7
  return ts.parseJsonConfigFileContent(configFile.config, ts.sys, basePath, {}, tsconfigPath);
8
8
  }
9
+ /** Create a one-shot TypeScript program suitable for production builds. */
10
+ export const createProgram = (tsconfigPath, compilerOptions) => {
11
+ const { fileNames } = getTSConfigFile(tsconfigPath);
12
+ return ts.createProgram(fileNames, compilerOptions);
13
+ };
9
14
  export const getCompilerOptions = (tsconfigPath) => {
10
15
  let compilerOptions = {
11
16
  jsx: ts.JsxEmit.React,
@@ -1 +1 @@
1
- {"version":3,"file":"vitePlugin.d.ts","sourceRoot":"","sources":["../../../lib/vitePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAC,KAAK,eAAe,EAAE,KAAK,OAAO,EAAC,MAAM,YAAY,CAAC;AAClE,OAAO,EAAC,KAAK,MAAM,EAAe,MAAM,MAAM,CAAC;AAQ/C,MAAM,WAAW,OAAO;IACtB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAChD,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAChD;;;QAGI;IACJ,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8EAA8E;IAC9E,eAAe,CAAC,EAAE,eAAe,CAAC;IAElC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC;IAE5F;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;CAClE;AAED,wBAAgB,oCAAoC,CAAC,MAAM,GAAE,OAAY,GAAG,MAAM,CA4DjF"}
1
+ {"version":3,"file":"vitePlugin.d.ts","sourceRoot":"","sources":["../../../lib/vitePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAC,KAAK,eAAe,EAAE,KAAK,OAAO,EAAC,MAAM,YAAY,CAAC;AAClE,OAAO,EAAC,KAAK,MAAM,EAAe,MAAM,MAAM,CAAC;AAQ/C,MAAM,WAAW,OAAO;IACtB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAChD,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAChD;;;QAGI;IACJ,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8EAA8E;IAC9E,eAAe,CAAC,EAAE,eAAe,CAAC;IAElC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC;IAE5F;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;CAClE;AAED,wBAAgB,oCAAoC,CAAC,MAAM,GAAE,OAAY,GAAG,MAAM,CA8EjF"}
@@ -1,22 +1,35 @@
1
1
  import ts from 'typescript';
2
2
  import { createFilter } from 'vite';
3
- import { getCompilerOptions, startWatch } from './createTypeScriptWatchProgram';
3
+ import { createProgram, getCompilerOptions, startWatch } from './createTypeScriptWatchProgram';
4
4
  export function vitePluginTypescriptWithTransformers(config = {}) {
5
5
  let tsProgram;
6
6
  let compilerOptions;
7
7
  let filter;
8
8
  const moduleInvalidationQueue = new Map();
9
+ // When the production (static) build runs, closeWatch is a no-op because there's no watch to close.
9
10
  let closeWatch;
11
+ // When the program is running in development with watch mode, tsProgram is a BuilderProgram.
12
+ // When the program is running in production, tsProgram is a Program.
13
+ // We need to get the Program from the BuilderProgram to get the correct source files.
14
+ const getProgram = () => ('getProgram' in tsProgram ? tsProgram.getProgram() : tsProgram);
10
15
  return {
11
16
  name: 'vite-plugin-typescript',
12
17
  enforce: 'pre',
13
- async configResolved() {
18
+ async configResolved(resolvedConfig) {
14
19
  var _a, _b, _c, _d;
15
20
  const tsconfigPath = (_a = config.tsconfigPath) !== null && _a !== void 0 ? _a : './tsconfig.json';
16
21
  compilerOptions = (_b = config.compilerOptions) !== null && _b !== void 0 ? _b : (await getCompilerOptions(tsconfigPath));
17
22
  const includeArray = (_c = config.include) !== null && _c !== void 0 ? _c : ['**/**.tsx?'];
18
23
  const excludeArray = (_d = config.exclude) !== null && _d !== void 0 ? _d : [];
19
24
  filter = createFilter(includeArray, excludeArray);
25
+ // If Vite is running a production (static) build, we need to create a new Program instead of running watch mode.
26
+ if (resolvedConfig.command === 'build') {
27
+ // Watch mode keeps the Node process alive after Vite finishes.
28
+ // Storybook's static build does not reliably call closeBundle before file writes.
29
+ tsProgram = createProgram(tsconfigPath, compilerOptions);
30
+ return;
31
+ }
32
+ // Watch mode is now only used for development builds.
20
33
  [tsProgram, closeWatch] = await startWatch(compilerOptions, tsconfigPath, program => {
21
34
  tsProgram = program;
22
35
  for (const [filepath, invalidateModule] of moduleInvalidationQueue.entries()) {
@@ -31,9 +44,9 @@ export function vitePluginTypescriptWithTransformers(config = {}) {
31
44
  return;
32
45
  }
33
46
  const printer = ts.createPrinter(compilerOptions);
34
- const transformers = ((_a = config.transformers) === null || _a === void 0 ? void 0 : _a.filter(t => t !== undefined).map(t => t(tsProgram.getProgram()))) ||
35
- [];
36
- const sourceFile = tsProgram.getSourceFile(id) || ts.createSourceFile(id, '', ts.ScriptTarget.ES2019);
47
+ const program = getProgram();
48
+ const transformers = ((_a = config.transformers) === null || _a === void 0 ? void 0 : _a.filter(t => t !== undefined).map(t => t(program))) || [];
49
+ const sourceFile = program.getSourceFile(id) || ts.createSourceFile(id, '', ts.ScriptTarget.ES2019);
37
50
  const transformed = printer.printFile(ts
38
51
  .transform(sourceFile, transformers, compilerOptions)
39
52
  .transformed.find(s => s.fileName === id) || sourceFile);
@@ -42,8 +55,13 @@ export function vitePluginTypescriptWithTransformers(config = {}) {
42
55
  : transformed;
43
56
  return postTransform || transformed;
44
57
  },
58
+ // Runs when the build finishes.
59
+ // This is an extra precaution in case Storybook / Vite don't call closeBundle before the process exits.
60
+ buildEnd() {
61
+ closeWatch === null || closeWatch === void 0 ? void 0 : closeWatch();
62
+ },
45
63
  closeBundle() {
46
- closeWatch();
64
+ closeWatch === null || closeWatch === void 0 ? void 0 : closeWatch();
47
65
  },
48
66
  };
49
67
  }
@@ -9,6 +9,15 @@ export function getTSConfigFile(tsconfigPath: string) {
9
9
  return ts.parseJsonConfigFileContent(configFile.config, ts.sys, basePath, {}, tsconfigPath);
10
10
  }
11
11
 
12
+ /** Create a one-shot TypeScript program suitable for production builds. */
13
+ export const createProgram = (
14
+ tsconfigPath: string,
15
+ compilerOptions: ts.CompilerOptions
16
+ ): ts.Program => {
17
+ const {fileNames} = getTSConfigFile(tsconfigPath);
18
+ return ts.createProgram(fileNames, compilerOptions);
19
+ };
20
+
12
21
  export const getCompilerOptions = (tsconfigPath: string) => {
13
22
  let compilerOptions: ts.CompilerOptions = {
14
23
  jsx: ts.JsxEmit.React,
package/lib/vitePlugin.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import ts, {type CompilerOptions, type Program} from 'typescript';
2
2
  import {type Plugin, createFilter} from 'vite';
3
3
 
4
- import {getCompilerOptions, startWatch} from './createTypeScriptWatchProgram';
4
+ import {createProgram, getCompilerOptions, startWatch} from './createTypeScriptWatchProgram';
5
5
 
6
6
  type Filepath = string;
7
7
  type InvalidateModule = () => void;
@@ -28,17 +28,22 @@ export interface Options {
28
28
  }
29
29
 
30
30
  export function vitePluginTypescriptWithTransformers(config: Options = {}): Plugin {
31
- let tsProgram: ts.BuilderProgram;
31
+ let tsProgram: ts.Program | ts.BuilderProgram;
32
32
  let compilerOptions: CompilerOptions;
33
33
  let filter: ReturnType<(typeof import('vite'))['createFilter']>;
34
34
  const moduleInvalidationQueue: Map<Filepath, InvalidateModule> = new Map();
35
- let closeWatch: CloseWatch;
35
+ // When the production (static) build runs, closeWatch is a no-op because there's no watch to close.
36
+ let closeWatch: CloseWatch | undefined;
37
+ // When the program is running in development with watch mode, tsProgram is a BuilderProgram.
38
+ // When the program is running in production, tsProgram is a Program.
39
+ // We need to get the Program from the BuilderProgram to get the correct source files.
40
+ const getProgram = () => ('getProgram' in tsProgram ? tsProgram.getProgram() : tsProgram);
36
41
 
37
42
  return {
38
43
  name: 'vite-plugin-typescript',
39
44
  enforce: 'pre',
40
45
 
41
- async configResolved() {
46
+ async configResolved(resolvedConfig) {
42
47
  const tsconfigPath = config.tsconfigPath ?? './tsconfig.json';
43
48
  compilerOptions = config.compilerOptions ?? (await getCompilerOptions(tsconfigPath));
44
49
 
@@ -46,6 +51,14 @@ export function vitePluginTypescriptWithTransformers(config: Options = {}): Plug
46
51
  const excludeArray = config.exclude ?? [];
47
52
 
48
53
  filter = createFilter(includeArray, excludeArray);
54
+ // If Vite is running a production (static) build, we need to create a new Program instead of running watch mode.
55
+ if (resolvedConfig.command === 'build') {
56
+ // Watch mode keeps the Node process alive after Vite finishes.
57
+ // Storybook's static build does not reliably call closeBundle before file writes.
58
+ tsProgram = createProgram(tsconfigPath, compilerOptions);
59
+ return;
60
+ }
61
+ // Watch mode is now only used for development builds.
49
62
  [tsProgram, closeWatch] = await startWatch(compilerOptions, tsconfigPath, program => {
50
63
  tsProgram = program;
51
64
 
@@ -62,13 +75,13 @@ export function vitePluginTypescriptWithTransformers(config: Options = {}): Plug
62
75
  }
63
76
 
64
77
  const printer = ts.createPrinter(compilerOptions);
78
+ const program = getProgram();
65
79
 
66
80
  const transformers =
67
- config.transformers?.filter(t => t !== undefined).map(t => t!(tsProgram.getProgram())) ||
68
- [];
81
+ config.transformers?.filter(t => t !== undefined).map(t => t!(program)) || [];
69
82
 
70
83
  const sourceFile =
71
- tsProgram.getSourceFile(id) || ts.createSourceFile(id, '', ts.ScriptTarget.ES2019);
84
+ program.getSourceFile(id) || ts.createSourceFile(id, '', ts.ScriptTarget.ES2019);
72
85
 
73
86
  const transformed = printer.printFile(
74
87
  ts
@@ -82,9 +95,14 @@ export function vitePluginTypescriptWithTransformers(config: Options = {}): Plug
82
95
 
83
96
  return postTransform || transformed;
84
97
  },
98
+ // Runs when the build finishes.
99
+ // This is an extra precaution in case Storybook / Vite don't call closeBundle before the process exits.
100
+ buildEnd() {
101
+ closeWatch?.();
102
+ },
85
103
 
86
104
  closeBundle() {
87
- closeWatch();
105
+ closeWatch?.();
88
106
  },
89
107
  };
90
108
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workday/canvas-kit-styling-transform",
3
- "version": "15.0.16",
3
+ "version": "15.0.18",
4
4
  "description": "The custom CSS in JS solution that takes JS styles and turns them into static CSS",
5
5
  "author": "Workday, Inc. (https://www.workday.com)",
6
6
  "license": "Apache-2.0",
@@ -45,7 +45,7 @@
45
45
  ],
46
46
  "dependencies": {
47
47
  "@emotion/serialize": "^1.0.2",
48
- "@workday/canvas-kit-styling": "^15.0.16",
48
+ "@workday/canvas-kit-styling": "^15.0.18",
49
49
  "@workday/canvas-tokens-web": "4.3.0",
50
50
  "stylis": "4.3.6",
51
51
  "ts-node": "^10.9.1",
@@ -58,5 +58,5 @@
58
58
  "peerDependencies": {
59
59
  "typescript": ">=5.0"
60
60
  },
61
- "gitHead": "616147d995d4671d7daf3233980d0034ae37c4f3"
61
+ "gitHead": "62a22061246b36d4c71174ed62e54eb517162399"
62
62
  }