Skip to content

Commit e737265

Browse files
committed
test: simplify esm loaders
1 parent 6b12397 commit e737265

File tree

52 files changed

+331
-562
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+331
-562
lines changed

demo/esm/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"mocha": {
1414
"inline-diffs": true,
15-
"loader": "./test/loaders/all.mjs",
15+
"loader": "./test/loaders/all.js",
1616
"recursive": true,
1717
"reporter": "spec",
1818
"require": [
@@ -23,6 +23,6 @@
2323
},
2424
"scripts": {
2525
"test": "mocha 'test/**/*.coffee'",
26-
"test:legacy": "mocha --loader=./test/loaders/legacy/all.mjs 'test/**/*.{coffee,ts}'"
26+
"test:legacy": "mocha --loader=./test/loaders/legacy/all.js 'test/**/*.{coffee,ts}'"
2727
}
2828
}

demo/esm/test/loaders/all.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
import * as coffee from './coffee.js'
3+
import * as ts from 'ts-node/esm'
4+
5+
const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
6+
const tsRegex = /\.ts$/;
7+
8+
export function load(url, context, next) {
9+
if (coffeeRegex.test(url)) {
10+
return coffee.load.apply(this, arguments)
11+
}
12+
if (tsRegex.test(url)) {
13+
return ts.load.apply(this, arguments)
14+
}
15+
return next(url, context, next);
16+
}

demo/esm/test/loaders/all.mjs

Lines changed: 0 additions & 26 deletions
This file was deleted.

demo/esm/test/loaders/coffee.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import CoffeeScript from 'coffeescript';
2+
3+
const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
4+
5+
export async function load(url, context, next) {
6+
if (coffeeRegex.test(url)) {
7+
const format = 'module';
8+
const { source: rawSource } = await next(url, { format });
9+
const source = CoffeeScript.compile(rawSource.toString(), { bare: true });
10+
return {format, source};
11+
}
12+
return next(url, context);
13+
}

demo/esm/test/loaders/coffee.mjs

Lines changed: 0 additions & 36 deletions
This file was deleted.

packages/csv-generate/test/loaders/legacy/all.mjs renamed to demo/esm/test/loaders/legacy/all.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import * as coffee from './coffee.mjs'
2+
import * as coffee from './coffee.js'
33
import * as ts from 'ts-node/esm'
44

55
const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;

demo/issues-esm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"mocha": {
1515
"inline-diffs": true,
16-
"loader": "./test/loaders/all.mjs",
16+
"loader": "./test/loaders/all.js",
1717
"recursive": true,
1818
"reporter": "spec",
1919
"require": [

demo/issues-esm/test/loaders/all.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
import * as coffee from './coffee.js'
3+
import * as ts from 'ts-node/esm'
4+
5+
const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
6+
const tsRegex = /\.ts$/;
7+
8+
export function load(url, context, next) {
9+
if (coffeeRegex.test(url)) {
10+
return coffee.load.apply(this, arguments)
11+
}
12+
if (tsRegex.test(url)) {
13+
return ts.load.apply(this, arguments)
14+
}
15+
return next(url, context, next);
16+
}

demo/issues-esm/test/loaders/all.mjs

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import CoffeeScript from 'coffeescript';
2+
3+
const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
4+
5+
export async function load(url, context, next) {
6+
if (coffeeRegex.test(url)) {
7+
const format = 'module';
8+
const { source: rawSource } = await next(url, { format });
9+
const source = CoffeeScript.compile(rawSource.toString(), { bare: true });
10+
return {format, source};
11+
}
12+
return next(url, context);
13+
}

demo/issues-esm/test/loaders/coffee.mjs

Lines changed: 0 additions & 36 deletions
This file was deleted.

demo/issues-esm/test/loaders/legacy/all.mjs renamed to demo/issues-esm/test/loaders/legacy/all.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import * as coffee from './coffee.mjs'
2+
import * as coffee from './coffee.js'
33
import * as ts from 'ts-node/esm'
44

55
const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;

packages/csv-generate/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"main": "./dist/cjs/index.cjs",
4949
"mocha": {
5050
"inline-diffs": true,
51-
"loader": "./test/loaders/all.mjs",
51+
"loader": "./test/loaders/all.js",
5252
"recursive": true,
5353
"reporter": "spec",
5454
"require": [
@@ -73,7 +73,7 @@
7373
"preversion": "npm run build && git add dist",
7474
"pretest": "npm run build",
7575
"test": "mocha 'test/**/*.{coffee,ts}'",
76-
"test:legacy": "mocha --loader=./test/loaders/legacy/all.mjs 'test/**/*.{coffee,ts}'"
76+
"test:legacy": "mocha --loader=./test/loaders/legacy/all.js 'test/**/*.{coffee,ts}'"
7777
},
7878
"type": "module",
7979
"types": "dist/esm/index.d.ts",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
import * as coffee from './coffee.js'
3+
import * as ts from 'ts-node/esm'
4+
5+
const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
6+
const tsRegex = /\.ts$/;
7+
8+
export function load(url, context, next) {
9+
if (coffeeRegex.test(url)) {
10+
return coffee.load.apply(this, arguments)
11+
}
12+
if (tsRegex.test(url)) {
13+
return ts.load.apply(this, arguments)
14+
}
15+
return next(url, context, next);
16+
}

packages/csv-generate/test/loaders/all.mjs

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import CoffeeScript from 'coffeescript';
2+
3+
const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
4+
5+
export async function load(url, context, next) {
6+
if (coffeeRegex.test(url)) {
7+
const format = 'module';
8+
const { source: rawSource } = await next(url, { format });
9+
const source = CoffeeScript.compile(rawSource.toString(), { bare: true });
10+
return {format, source};
11+
}
12+
return next(url, context);
13+
}

packages/csv-generate/test/loaders/coffee.mjs

Lines changed: 0 additions & 36 deletions
This file was deleted.

demo/esm/test/loaders/legacy/all.mjs renamed to packages/csv-generate/test/loaders/legacy/all.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import * as coffee from './coffee.mjs'
2+
import * as coffee from './coffee.js'
33
import * as ts from 'ts-node/esm'
44

55
const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;

packages/csv-parse/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"main": "./dist/cjs/index.cjs",
7272
"mocha": {
7373
"inline-diffs": true,
74-
"loader": "./test/loaders/all.mjs",
74+
"loader": "./test/loaders/all.js",
7575
"recursive": true,
7676
"reporter": "spec",
7777
"require": [
@@ -96,7 +96,7 @@
9696
"preversion": "npm run build && git add dist",
9797
"pretest": "npm run build",
9898
"test": "mocha 'test/**/*.{coffee,ts}'",
99-
"test:legacy": "mocha --loader=./test/loaders/legacy/all.mjs 'test/**/*.{coffee,ts}'"
99+
"test:legacy": "mocha --loader=./test/loaders/legacy/all.js 'test/**/*.{coffee,ts}'"
100100
},
101101
"type": "module",
102102
"types": "dist/esm/index.d.ts",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
import * as coffee from './coffee.js'
3+
import * as ts from 'ts-node/esm'
4+
5+
const coffeeRegex = /\.coffee$|\.litcoffee$|\.coffee\.md$/;
6+
const tsRegex = /\.ts$/;
7+
8+
export function load(url, context, next) {
9+
if (coffeeRegex.test(url)) {
10+
return coffee.load.apply(this, arguments)
11+
}
12+
if (tsRegex.test(url)) {
13+
return ts.load.apply(this, arguments)
14+
}
15+
return next(url, context, next);
16+
}

0 commit comments

Comments
 (0)