Skip to content

Commit 0adfa14

Browse files
committed
Theme: Fix build failure of mode overrides plugin on Windows OS
1 parent d3734f5 commit 0adfa14

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

packages/theme/bin/terrazzo-plugin-mode-overrides/index.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* External dependencies
33
*/
4-
import { basename, join, dirname } from 'node:path';
4+
import { basename, join } from 'node:path';
55
import { fileURLToPath } from 'node:url';
66
import type { Plugin } from '@terrazzo/parser';
77

@@ -155,9 +155,13 @@ function getModeOverrides(
155155
* For each mode found in tokens (via $extensions.mode), generates a separate
156156
* JSON file per source file containing tokens that have values for that mode.
157157
*
158+
* @param options Plugin options.
159+
* @param options.filePath Output path relative to outDir (default: 'modes').
158160
* @return A Terrazzo plugin that generates mode-specific DTCG override files.
159161
*/
160-
export default function pluginModeOverrides(): Plugin {
162+
export default function pluginModeOverrides( {
163+
filePath = 'modes',
164+
} = {} ): Plugin {
161165
return {
162166
name: '@wordpress/terrazzo-plugin-mode-overrides',
163167
async build( { outputFile, sources } ) {
@@ -189,13 +193,20 @@ export default function pluginModeOverrides(): Plugin {
189193
}
190194

191195
// Output as {basename}.{mode}.json (e.g., dimension.compact.json)
192-
const filePath = fileURLToPath( filename );
193-
const outFile = join(
194-
dirname( filePath ),
195-
'modes',
196-
`${ basename( filePath, '.json' ) }.${ mode }.json`
196+
const jsonFileName = `${ basename(
197+
fileURLToPath( filename ),
198+
'.json'
199+
) }.${ mode }.json`;
200+
201+
const outputFilePath = join(
202+
filePath,
203+
jsonFileName
204+
).replace( /\\/g, '/' );
205+
206+
outputFile(
207+
outputFilePath,
208+
JSON.stringify( output, null, '\t' )
197209
);
198-
outputFile( outFile, JSON.stringify( output, null, '\t' ) );
199210
}
200211
}
201212
},

packages/theme/terrazzo.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ export default defineConfig( {
7575
pluginDsTokenDocs( {
7676
filename: '../../docs/ds-tokens.md',
7777
} ),
78-
pluginModeOverrides(),
78+
pluginModeOverrides( {
79+
filePath: '../../tokens/modes',
80+
} ),
7981
],
8082

8183
// Linter rules current error when multiple entry files are used

0 commit comments

Comments
 (0)