Skip to content

Commit

Permalink
WIP attempt at making "type":"module" work
Browse files Browse the repository at this point in the history
  • Loading branch information
kainino0x committed Nov 13, 2023
1 parent 2032e16 commit a90bc7f
Show file tree
Hide file tree
Showing 18 changed files with 24 additions and 17 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (api) {
export default function (api) {
api.cache(true);
return {
presets: ['@babel/preset-typescript'],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@webgpu/cts",
"version": "0.1.0",
"description": "WebGPU Conformance Test Suite",
"type": "module",
"scripts": {
"test": "grunt all",
"all": "grunt all",
Expand Down
6 changes: 3 additions & 3 deletions src/common/runtime/helper/sys.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint no-process-exit: "off" */
/* eslint @typescript-eslint/no-namespace: "off" */

function node() {
const { existsSync } = require('fs');
async function node() {
const { existsSync } = await import('fs');

return {
type: 'node',
Expand Down Expand Up @@ -41,6 +41,6 @@ function deno() {
};
}

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

export default sys;
3 changes: 3 additions & 0 deletions src/common/tools/commonjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');
// Automatically transpile .ts imports
require('ts-node').register({
// Specify the project file so ts-node doesn't try to find it itself based on the CWD.
project: path.resolve(__dirname, '../../../tsconfig.json'),
project: path.resolve(__dirname, '../../../../tsconfig.json'),
compilerOptions: {
module: 'commonjs',
},
Expand Down
2 changes: 1 addition & 1 deletion src/common/tools/version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const version = require('child_process')
export const version = (await import('child_process'))
.execSync('git describe --always --abbrev=0 --dirty')
.toString()
.trim();
2 changes: 1 addition & 1 deletion tools/checklist
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
// and every query in it is valid (e.g. renames have been applied, and new tests added
// to the spreadsheet have also been added to the CTS).

require('../src/common/tools/setup-ts-in-node.js');
require('../src/common/tools/commonjs/setup-ts-in-node.js');
require('../src/common/tools/checklist.ts');
2 changes: 1 addition & 1 deletion tools/dev_server
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node

require('../src/common/tools/setup-ts-in-node.js');
require('../src/common/tools/commonjs/setup-ts-in-node.js');
require('../src/common/tools/dev_server.ts');
2 changes: 1 addition & 1 deletion tools/gen_cache
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node

require('../src/common/tools/setup-ts-in-node.js');
require('../src/common/tools/commonjs/setup-ts-in-node.js');
require('../src/common/tools/gen_cache.ts');
2 changes: 1 addition & 1 deletion tools/gen_listings
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
// Crawl a suite directory (e.g. src/webgpu/) to generate a listing.js containing
// the listing of test files in the suite.

require('../src/common/tools/setup-ts-in-node.js');
require('../src/common/tools/commonjs/setup-ts-in-node.js');
require('../src/common/tools/gen_listings.ts');
4 changes: 2 additions & 2 deletions tools/gen_version
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/* eslint-disable no-console */

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

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

const { version } = require('../src/common/tools/version.ts');
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

fs.mkdirSync('./gen/common/internal', { recursive: true });
// This will be copied into the various other build directories.
Expand Down
2 changes: 1 addition & 1 deletion tools/gen_wpt_cts_html
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
// ?q=webgpu:a/bar:bar1={"x":3} <- [ Mac ]
// ?q=webgpu:a/bar:bar2~

require('../src/common/tools/setup-ts-in-node.js');
require('../src/common/tools/commonjs/setup-ts-in-node.js');
require('../src/common/tools/gen_wpt_cts_html.ts');
2 changes: 1 addition & 1 deletion tools/merge_listing_times
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// See `docs/adding_timing_metadata.md` for an explanation of listing times, and
// a walkthrough on adding entries for new tests.

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

// See the help message in this file for info on how to use the tool.
require('../src/common/tools/merge_listing_times.ts');
3 changes: 3 additions & 0 deletions tools/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
2 changes: 1 addition & 1 deletion tools/run_node
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

// Run test suites under node.

require('../src/common/tools/setup-ts-in-node.js');
require('../src/common/tools/commonjs/setup-ts-in-node.js');
require('../src/common/runtime/cmdline.ts');
2 changes: 1 addition & 1 deletion tools/run_wpt_ref_tests
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node

require('../src/common/tools/setup-ts-in-node.js');
require('../src/common/tools/commonjs/setup-ts-in-node.js');
require('../src/common/tools/run_wpt_ref_tests.ts');
2 changes: 1 addition & 1 deletion tools/validate
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

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

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

0 comments on commit a90bc7f

Please sign in to comment.