Skip to content

Commit 3cde453

Browse files
committed
WIP attempt at making "type":"module" work
1 parent 2032e16 commit 3cde453

18 files changed

+21
-17
lines changed
File renamed without changes.

babel.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = function (api) {
1+
export default function (api) {
22
api.cache(true);
33
return {
44
presets: ['@babel/preset-typescript'],

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@webgpu/cts",
33
"version": "0.1.0",
44
"description": "WebGPU Conformance Test Suite",
5+
"type": "module",
56
"scripts": {
67
"test": "grunt all",
78
"all": "grunt all",

src/common/runtime/helper/sys.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint no-process-exit: "off" */
22
/* eslint @typescript-eslint/no-namespace: "off" */
33

4-
function node() {
5-
const { existsSync } = require('fs');
4+
async function node() {
5+
const { existsSync } = await import('fs');
66

77
return {
88
type: 'node',
@@ -41,6 +41,6 @@ function deno() {
4141
};
4242
}
4343

44-
const sys = typeof globalThis.process !== 'undefined' ? node() : deno();
44+
const sys = typeof globalThis.process !== 'undefined' ? await node() : deno();
4545

4646
export default sys;

src/common/tools/commonjs/package.json

Whitespace-only changes.

src/common/tools/setup-ts-in-node.js renamed to src/common/tools/commonjs/setup-ts-in-node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const path = require('path');
33
// Automatically transpile .ts imports
44
require('ts-node').register({
55
// Specify the project file so ts-node doesn't try to find it itself based on the CWD.
6-
project: path.resolve(__dirname, '../../../tsconfig.json'),
6+
project: path.resolve(__dirname, '../../../../tsconfig.json'),
77
compilerOptions: {
88
module: 'commonjs',
99
},

src/common/tools/version.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const version = require('child_process')
1+
export const version = (await import('child_process'))
22
.execSync('git describe --always --abbrev=0 --dirty')
33
.toString()
44
.trim();

tools/checklist

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
// and every query in it is valid (e.g. renames have been applied, and new tests added
88
// to the spreadsheet have also been added to the CTS).
99

10-
require('../src/common/tools/setup-ts-in-node.js');
10+
require('../src/common/tools/commonjs/setup-ts-in-node.js');
1111
require('../src/common/tools/checklist.ts');

tools/dev_server

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env node
22

3-
require('../src/common/tools/setup-ts-in-node.js');
3+
require('../src/common/tools/commonjs/setup-ts-in-node.js');
44
require('../src/common/tools/dev_server.ts');

tools/gen_cache

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env node
22

3-
require('../src/common/tools/setup-ts-in-node.js');
3+
require('../src/common/tools/commonjs/setup-ts-in-node.js');
44
require('../src/common/tools/gen_cache.ts');

tools/gen_listings

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
// Crawl a suite directory (e.g. src/webgpu/) to generate a listing.js containing
44
// the listing of test files in the suite.
55

6-
require('../src/common/tools/setup-ts-in-node.js');
6+
require('../src/common/tools/commonjs/setup-ts-in-node.js');
77
require('../src/common/tools/gen_listings.ts');

tools/gen_version

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
/* eslint-disable no-console */
77

8-
require('../src/common/tools/setup-ts-in-node.js');
8+
require('../src/common/tools/commonjs/setup-ts-in-node.js');
99
const fs = require('fs');
1010

1111
const myself = 'tools/gen_version';
@@ -14,7 +14,7 @@ if (!fs.existsSync(myself)) {
1414
process.exit(1);
1515
}
1616

17-
const { version } = require('../src/common/tools/version.ts');
17+
const { version } = require('../src/common/tools/version.ts'); // FIXME doesn't work because in order to require the placeholder version.ts it needs to be commonjs, but we can't configure that for a single file
1818

1919
fs.mkdirSync('./gen/common/internal', { recursive: true });
2020
// This will be copied into the various other build directories.

tools/gen_wpt_cts_html

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@
3535
// ?q=webgpu:a/bar:bar1={"x":3} <- [ Mac ]
3636
// ?q=webgpu:a/bar:bar2~
3737

38-
require('../src/common/tools/setup-ts-in-node.js');
38+
require('../src/common/tools/commonjs/setup-ts-in-node.js');
3939
require('../src/common/tools/gen_wpt_cts_html.ts');

tools/merge_listing_times

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// See `docs/adding_timing_metadata.md` for an explanation of listing times, and
44
// a walkthrough on adding entries for new tests.
55

6-
require('../src/common/tools/setup-ts-in-node.js');
6+
require('../src/common/tools/commonjs/setup-ts-in-node.js');
77

88
// See the help message in this file for info on how to use the tool.
99
require('../src/common/tools/merge_listing_times.ts');

tools/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}

tools/run_node

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
// Run test suites under node.
44

5-
require('../src/common/tools/setup-ts-in-node.js');
5+
require('../src/common/tools/commonjs/setup-ts-in-node.js');
66
require('../src/common/runtime/cmdline.ts');

tools/run_wpt_ref_tests

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env node
22

3-
require('../src/common/tools/setup-ts-in-node.js');
3+
require('../src/common/tools/commonjs/setup-ts-in-node.js');
44
require('../src/common/tools/run_wpt_ref_tests.ts');

tools/validate

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
// Validate several properties of test files and the tests in them.
44

5-
require('../src/common/tools/setup-ts-in-node.js');
5+
require('../src/common/tools/commonjs/setup-ts-in-node.js');
66
require('../src/common/tools/validate.ts');

0 commit comments

Comments
 (0)