Skip to content

Commit

Permalink
Merge pull request #2549 from koddsson/remove-code-for-old-node-versions
Browse files Browse the repository at this point in the history
Remove old node runtime specific code
  • Loading branch information
koddsson authored Nov 11, 2023
2 parents f559302 + 5b6e1bc commit 6eceb7e
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 50 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-ads-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@web/config-loader': patch
---

Drop support for older node runtimes (12 and earlier)
3 changes: 0 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/config-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"es module"
],
"dependencies": {
"semver": "^7.3.4"
},
"types": "dist/index.d.ts",
"exports": {
Expand Down
11 changes: 0 additions & 11 deletions packages/config-loader/src/importConfig.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
const semver = require('semver');
const { pathToFileURL } = require('url');
const ConfigLoaderError = require('./ConfigLoaderError');

const supportsEsm = semver.satisfies(process.version, '>=12.17.0');

// These strings may be node-version dependent and need updating over time
// They're just to display a helpful error message
const CJS_ERRORS = [
Expand All @@ -16,14 +13,6 @@ const CJS_ERRORS = [
* @param {string} path
*/
async function importConfig(path) {
if (!supportsEsm) {
throw new ConfigLoaderError(
'You are trying to load a config as es module but your version of node does not support it. ' +
'Update to node v12.17.0 or higher, or load the config as commonjs by using the .cjs extension ' +
'or .js without type="module" set in your package.json',
);
}

try {
const config = await import(pathToFileURL(path).href);

Expand Down
35 changes: 0 additions & 35 deletions packages/config-loader/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const path = require('path');
const { expect } = require('chai');
const semver = require('semver');
const { readConfig } = require('../src/index');

// some tests are specific for node < v12.17.0
const supportsEsm = semver.satisfies(process.version, '>=12.17.0');
const configName = 'my-project.config';
const packageCjsPath = path.resolve(__dirname, 'fixtures', 'package-cjs');
const packageMjsPath = path.resolve(__dirname, 'fixtures', 'package-mjs');
Expand Down Expand Up @@ -41,7 +38,6 @@ describe('cjs package', () => {
expect(result).to.eql({ foo: 'bar' });
});

if (supportsEsm) {
it('can load module-in-.mjs', async () => {
const result = await readConfig(
configName,
Expand All @@ -50,11 +46,6 @@ describe('cjs package', () => {
);
expect(result).to.eql({ foo: 'bar' });
});
} else {
it('throws an error when trying to load a mjs file', async () => {
await expectThrowsOldNodeError(path.resolve(packageCjsPath, 'module-in-.mjs'));
});
}

it('throws when loading module-in-.cjs', async () => {
let thrown = false;
Expand Down Expand Up @@ -82,7 +73,6 @@ describe('cjs package', () => {
expect(thrown).to.equal(true);
});

if (supportsEsm) {
it('throws when loading commonjs-in-.mjs', async () => {
let thrown = false;
try {
Expand All @@ -95,7 +85,6 @@ describe('cjs package', () => {
}
expect(thrown).to.equal(true);
});
}
});

describe('mjs package', () => {
Expand All @@ -108,7 +97,6 @@ describe('mjs package', () => {
expect(result).to.eql({ foo: 'bar' });
});

if (supportsEsm) {
it('throws when loading commonjs-in-.js', async () => {
let thrown = false;
try {
Expand All @@ -121,13 +109,7 @@ describe('mjs package', () => {
}
expect(thrown).to.equal(true);
});
} else {
it('throws an error when trying to load commonjs-in-.js', async () => {
await expectThrowsOldNodeError(path.resolve(packageMjsPath, 'commonjs-in-.js'));
});
}

if (supportsEsm) {
it('throws when loading commonjs-in-.mjs', async () => {
let thrown = false;
try {
Expand All @@ -140,11 +122,6 @@ describe('mjs package', () => {
}
expect(thrown).to.equal(true);
});
} else {
it('throws an error when trying to load commonjs-in-.mjs', async () => {
await expectThrowsOldNodeError(path.resolve(packageMjsPath, 'commonjs-in-.mjs'));
});
}

it('throws when loading module-in-.cjs', async () => {
let thrown = false;
Expand All @@ -159,7 +136,6 @@ describe('mjs package', () => {
expect(thrown).to.equal(true);
});

if (supportsEsm) {
it('can load module-in-.js', async () => {
const result = await readConfig(
configName,
Expand All @@ -168,13 +144,7 @@ describe('mjs package', () => {
);
expect(result).to.eql({ foo: 'bar' });
});
} else {
it('throws an error when trying to load module-in-.js', async () => {
await expectThrowsOldNodeError(path.resolve(packageMjsPath, 'module-in-.js'));
});
}

if (supportsEsm) {
it('can load module-in-.mjs', async () => {
const result = await readConfig(
configName,
Expand All @@ -183,9 +153,4 @@ describe('mjs package', () => {
);
expect(result).to.eql({ foo: 'bar' });
});
} else {
it('throws an error when trying to load a mjs file', async () => {
await expectThrowsOldNodeError(path.resolve(packageMjsPath, 'module-in-.mjs'));
});
}
});

0 comments on commit 6eceb7e

Please sign in to comment.