Skip to content

Commit

Permalink
ESM all the things
Browse files Browse the repository at this point in the history
This PR changes all internal code (scripts/, test/, util/) to ESM. The
built package for NPM now contains an ESM and CJS entrypoint.
  • Loading branch information
lucacasonato committed Aug 23, 2021
1 parent d983331 commit e5aa6ad
Show file tree
Hide file tree
Showing 56 changed files with 2,074 additions and 369 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ npm install @mdn/browser-compat-data
## Usage

```js
const bcd = require('@mdn/browser-compat-data');
import bcd from '@mdn/browser-compat-data';
bcd.css.properties.background;
// returns a compat data object (see schema)
```
Expand Down
7 changes: 2 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/// <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;
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
const fs = require('fs');
const path = require('path');
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

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

function load() {
// Recursively load one or more directories passed as arguments.
Expand Down Expand Up @@ -32,7 +34,7 @@ function load() {
}

for (dir of arguments) {
dir = path.resolve(__dirname, dir);
dir = path.resolve(dirname, dir);
fs.readdirSync(dir).forEach(processFilename);
}

Expand All @@ -59,7 +61,7 @@ function extend(target, source) {
}
}

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

0 comments on commit e5aa6ad

Please sign in to comment.