@@ -192,16 +192,16 @@ const writeFilesForCache = ({
192
192
T . succeedWith ( ( ) => process . versions . node . split ( '.' ) . map ( ( _ ) => parseInt ( _ , 10 ) ) as [ number , number , number ] ) ,
193
193
)
194
194
195
- // NOTE Type assert statements for `.json` files are neccessary from Node v16.14 onwards
196
- const needsJsonAssertStatement = nodeVersionMajor > 16 || ( nodeVersionMajor === 16 && nodeVersionMinor >= 14 )
197
- const assertStatement = needsJsonAssertStatement ? ` assert { type: 'json' }` : ''
195
+ // NOTE: An import attribute for `.json` files is neccessary from Node v16.14 onwards.
196
+ const needsTypeJsonAttribute = nodeVersionMajor > 16 || ( nodeVersionMajor === 16 && nodeVersionMinor >= 14 )
197
+ const importAttributeStatement = needsJsonimportAttributeStatement ? ` with { type: 'json' }` : ''
198
198
199
199
const typeNameField = generationOptions . options . fieldOptions . typeFieldName
200
200
const dataBarrelFiles = documentDefs . map ( ( docDef ) => ( {
201
201
content : makeDataExportFile ( {
202
202
docDef,
203
203
documentIds : allDocuments . filter ( ( _ ) => _ [ typeNameField ] === docDef . name ) . map ( ( _ ) => _ . _id ) ,
204
- assertStatement ,
204
+ importAttributeStatement ,
205
205
} ) ,
206
206
filePath : withPrefix ( 'generated' , docDef . name , `_index.mjs` ) ,
207
207
} ) )
@@ -255,7 +255,7 @@ const writeFilesForCache = ({
255
255
filePath : withPrefix ( 'generated' , 'index.mjs' ) ,
256
256
content : makeIndexMjs ( {
257
257
schemaDef,
258
- assertStatement ,
258
+ importAttributeStatement ,
259
259
bundleFilePath : relativeBundleFilePath ,
260
260
isDev,
261
261
options,
@@ -338,19 +338,19 @@ const writeFileWithWrittenFilesCache =
338
338
const makeDataExportFile = ( {
339
339
docDef,
340
340
documentIds,
341
- assertStatement ,
341
+ importAttributeStatement ,
342
342
} : {
343
343
docDef : DocumentTypeDef
344
344
documentIds : string [ ]
345
- assertStatement : string
345
+ importAttributeStatement : string
346
346
} ) : string => {
347
347
const dataVariableName = getDataVariableName ( { docDef } )
348
348
349
349
if ( docDef . isSingleton ) {
350
350
const documentId = documentIds [ 0 ] !
351
351
return `\
352
352
// ${ autogeneratedNote }
353
- export { default as ${ dataVariableName } } from './${ idToFileName ( documentId ) } .json'${ assertStatement }
353
+ export { default as ${ dataVariableName } } from './${ idToFileName ( documentId ) } .json'${ importAttributeStatement }
354
354
`
355
355
}
356
356
@@ -376,7 +376,7 @@ export { default as ${dataVariableName} } from './${idToFileName(documentId)}.js
376
376
)
377
377
378
378
const docImports = documentIds
379
- . map ( ( _ ) => `import ${ idToVariableNameMap . get ( _ ) } from './${ idToFileName ( _ ) } .json'${ assertStatement } ` )
379
+ . map ( ( _ ) => `import ${ idToVariableNameMap . get ( _ ) } from './${ idToFileName ( _ ) } .json'${ importAttributeStatement } ` )
380
380
. join ( '\n' )
381
381
382
382
return `\
@@ -390,13 +390,13 @@ export const ${dataVariableName} = [${Array.from(idToVariableNameMap.values()).j
390
390
391
391
const makeIndexMjs = ( {
392
392
schemaDef,
393
- assertStatement ,
393
+ importAttributeStatement ,
394
394
bundleFilePath,
395
395
options,
396
396
isDev,
397
397
} : {
398
398
schemaDef : SchemaDef
399
- assertStatement : string
399
+ importAttributeStatement : string
400
400
bundleFilePath : RelativePosixFilePath
401
401
options : PluginOptions
402
402
isDev : boolean
@@ -413,7 +413,7 @@ const makeIndexMjs = ({
413
413
. map ( ( { documentDefName, dataVariableName } ) =>
414
414
isDev
415
415
? `import { ${ dataVariableName } } from './${ documentDefName } /_index.mjs'`
416
- : `import ${ dataVariableName } from './${ documentDefName } /_index.json'${ assertStatement } ` ,
416
+ : `import ${ dataVariableName } from './${ documentDefName } /_index.json'${ importAttributeStatement } ` ,
417
417
)
418
418
. join ( '\n' )
419
419
@@ -434,7 +434,7 @@ export const fetchContent = async (sourceKey) => {
434
434
const worker = new Worker(workerFilePath, { workerData: { sourceKey } })
435
435
436
436
return new Promise((resolve, reject) => {
437
- worker.on('message', (data) => {
437
+ worker.on('message', (data) => {
438
438
if (data.result) {
439
439
resolve(data.result)
440
440
} else if (data.fatalError) {
@@ -485,7 +485,7 @@ export const makeDataTypes = ({ schemaDef, options }: { schemaDef: SchemaDef; op
485
485
if ( options . experimental . enableDynamicBuild === false ) return ''
486
486
487
487
return `\
488
- export type FetchContentResult =
488
+ export type FetchContentResult =
489
489
| { _tag: 'Error', error: SourceProvideSchemaErrorJSON | SourceFetchDataErrorJSON }
490
490
| { _tag: 'Data', data: DataExports }
491
491
0 commit comments