-
-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* json / wasm import assertion support. * Addressing review feedback * reformat * fix mistakes in test * add node 17 stable to test matrix Co-authored-by: Andrew Bradley <abradley@brightcove.com> Co-authored-by: Andrew Bradley <cspotcode@gmail.com>
- Loading branch information
1 parent
a817289
commit 89f88eb
Showing
16 changed files
with
152 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"color": "fuchsia", | ||
"doors": "open", | ||
"seats": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import carData from './car.json' assert { type: 'json' }; | ||
|
||
if (carData.color !== 'fuchsia') throw new Error('failed to import json'); | ||
|
||
const { default: dynamicCarData } = await import('./car.json', { | ||
assert: { type: 'json' }, | ||
}); | ||
|
||
if (dynamicCarData.doors !== 'open') | ||
throw new Error('failed to dynamically import json'); | ||
|
||
console.log( | ||
`A ${carData.color} car has ${carData.seats} seats and the doors are ${dynamicCarData.doors}.` | ||
); | ||
|
||
// Test that omitting the assertion causes node to throw an error | ||
await import('./car.json').then( | ||
() => { | ||
throw new Error('should have thrown'); | ||
}, | ||
(error: any) => { | ||
if (error.code !== 'ERR_IMPORT_ASSERTION_TYPE_MISSING') { | ||
throw error; | ||
} | ||
/* error is expected */ | ||
} | ||
); | ||
console.log('Done!'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "ESNext", | ||
"target": "ESNext", | ||
"resolveJsonModule": true, | ||
"allowJs": true, | ||
"moduleResolution": "node", | ||
"allowSyntheticDefaultImports": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as moduleA from './moduleA.mjs'; | ||
import * as moduleB from './moduleB.mjs' assert { foo: 'bar' }; | ||
import * as jsonModule from './jsonModuleA.json' assert { type: 'json' }; | ||
|
||
await import('./moduleC.mjs'); | ||
await import('./moduleD.mjs', { foo: 'bar' }); | ||
await import('./jsonModuleB.json', { assert: { type: 'json' } }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function resolve(specifier, context, defaultResolve) { | ||
console.log(JSON.stringify({ resolveContextKeys: Object.keys(context) })); | ||
return defaultResolve(specifier, context); | ||
} | ||
export function load(url, context, defaultLoad) { | ||
console.log(JSON.stringify({ loadContextKeys: Object.keys(context) })); | ||
return defaultLoad(url, context); | ||
} |
Empty file.
Empty file.
Empty file.
Empty file.