Skip to content

Commit

Permalink
ESM all the things (#12161)
Browse files Browse the repository at this point in the history
* ESM all the things

This PR changes all internal code (scripts/, test/, util/) to ESM. The
built package for NPM now contains an ESM and CJS entrypoint.

* Fix formatting

* Add missing import

* Fix remaining files

* Install es-main package

* Utilize es-main package

* Import yargs hideBin() helper

* Fix exports

* Wrap yargs/executable script parts within esMain

* Fix yargs

* Fix imports

* Move main function down in diff-features

* Fix exports for diff-features

* Fix release-notes script

* Fix enumerate-features

* review comments

* Fix imports and exports

* Fix imports/exports, cleanup code, cleanup diff, fix scripts

* Fix import

* Use import assertion for browser-specs (we're using NodeJS v16)

* Fix ESLint

* Fix unittest

* Fix unittest (again)

Co-authored-by: Queen Vinyl Da.i'gyu-Kazotetsu <[email protected]>
  • Loading branch information
lucacasonato and queengooborg authored May 18, 2022
1 parent b73a46f commit 9e00860
Show file tree
Hide file tree
Showing 62 changed files with 1,852 additions and 928 deletions.
3 changes: 3 additions & 0 deletions .babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["@babel/plugin-syntax-import-assertions"]
}
5 changes: 3 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"env": {
"commonjs": true,
"es6": true,
"jest": true,
"node": true
Expand All @@ -10,7 +9,9 @@
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 2020
"ecmaVersion": 2020,
"sourceType": "module"
}
}
6 changes: 1 addition & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
/* This file is a part of @mdn/browser-compat-data
* See LICENSE file for more information. */

/// <reference path="./types.d.ts"/>
import { CompatData } from './types';

// This is necessary to have intellisense in projects which
// import data from this package.
declare const compatData: CompatData;
export = compatData;
export default CompatData;
14 changes: 8 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* This file is a part of @mdn/browser-compat-data
* See LICENSE file for more information. */

'use strict';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const fs = require('fs');
const path = require('path');
const { fdir } = require('fdir');
import { fdir } from 'fdir';

const dirname = fileURLToPath(new URL('.', import.meta.url));

class DuplicateCompatError extends Error {
constructor(feature) {
Expand All @@ -27,7 +29,7 @@ function load(...dirs) {
const paths = new fdir()
.withBasePath()
.filter((fp) => fp.endsWith('.json'))
.crawl(path.join(__dirname, dir))
.crawl(path.join(dirname, dir))
.sync();

for (const fp of paths) {
Expand Down Expand Up @@ -67,7 +69,7 @@ function extend(target, source, feature = '') {
}
}

module.exports = load(
export default load(
'api',
'browsers',
'css',
Expand Down
Loading

0 comments on commit 9e00860

Please sign in to comment.