Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

feat: ESM modules support #1323

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions test/test-00-esm/main.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env node

'use strict';

const path = require('path');
const assert = require('assert');
const utils = require('../utils.js');
const os = require('os');

const MAJOR_VERSION = parseInt(process.version.match(/v([0-9]+)/)[1], 10);

if (MAJOR_VERSION < 14) {
console.log(
'skiping test as it requires nodejs >= 14',
MAJOR_VERSION
);
return;
}

assert(__dirname === process.cwd());

const ext = process.platform === 'win32' ? '.exe' : '';

const target = process.argv[2] || 'host';
const input = './test.js';
const output = './test-output' + ext;

console.log('target = ', target);
utils.pkg.sync([
'--target',
target,
'--output',
output,
input,
]);

// check that produced executable is running and produce the expected output.
const log = utils.spawn.sync(output, [], {
cwd: path.dirname(output),
expect: 0,
});
assert(log === os.arch() + '\n');

// clean up
utils.vacuum.sync(output);

console.log('OK');
13 changes: 13 additions & 0 deletions test/test-00-esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "test-00-esm",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "test.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
Binary file added test/test-00-esm/test-output
Binary file not shown.
3 changes: 3 additions & 0 deletions test/test-00-esm/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import os from 'os';

console.log(os.arch());
7 changes: 5 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ function joinAndForward(d) {
const list = [];

if (flavor.match(/^test/)) {
list.push(joinAndForward(`${flavor}/main.js`));
list.push(
joinAndForward(`${flavor}/main.js`),
joinAndForward(`${flavor}/main.cjs`)
);
} else if (flavor === 'only-npm') {
list.push(joinAndForward('test-79-npm/main.js'));
} else {
list.push(joinAndForward('**/main.js'));
list.push(joinAndForward('**/main.js'), joinAndForward('**/main.cjs'));
if (flavor === 'no-npm') {
list.push('!' + joinAndForward('test-42-fetch-all'));
list.push('!' + joinAndForward('test-46-multi-arch'));
Expand Down