Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Package data for NPM as ESM and CJS" #15774

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@ npm install @mdn/browser-compat-data
## Usage

```js
// Import BCD into your project
import bcd from '@mdn/browser-compat-data';
// ...or...
const bcd = require('@mdn/browser-compat-data');

// Grab the desired support statement
const support = bcd.css.properties.background;
bcd.css.properties.background;
// returns a compat data object (see schema)
```

Expand Down
7 changes: 5 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */

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

export default CompatData;
// This is necessary to have intellisense in projects which
// import data from this package.
declare const compatData: CompatData;
export = compatData;
19 changes: 7 additions & 12 deletions scripts/release-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ function createDataBundle() {
}

// Returns a promise for writing the data to JSON file
async function writeData(data) {
async function writeData() {
const dest = path.resolve(directory, 'data.json');
const data = createDataBundle();
await fs.writeFile(dest, data);
}

async function writeIndexESM(data) {
async function writeIndex() {
const dest = path.resolve(directory, 'index.js');
const content = `export default ${data};\n`;
const content = `module.exports = require("./data.json");\n`;
await fs.writeFile(dest, content);
}

Expand All @@ -37,11 +38,7 @@ async function copyFiles() {

function createManifest() {
const full = require('../package.json');
const minimal = {
main: 'data.json',
exports: { import: './index.js', require: './data.json' },
type: 'module',
};
const minimal = { main: 'index.js' };

const minimalKeys = [
'name',
Expand Down Expand Up @@ -87,11 +84,9 @@ async function main() {
// Crate a new directory
await fs.mkdir(directory);

const data = createDataBundle();

await writeManifest();
await writeData(data);
await writeIndexESM(data);
await writeData();
await writeIndex();
await copyFiles();

console.log('Data bundle is ready');
Expand Down
20 changes: 5 additions & 15 deletions scripts/release-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,13 @@
const assert = require('assert');
const { execSync } = require('child_process');

const prebuiltCjsPath = '../build';
const prebuiltJsPath = '../build/index.js';

const regular = require('..');
const prebuiltPath = '../build';

describe('release-build', () => {
before(() => {
it('pre-built bundles are identical to the source', () => {
execSync('npm run release-build');
});

it('pre-built cjs bundles are identical to the source', () => {
const bundled = require(prebuiltCjsPath);
assert.deepEqual(regular, bundled);
}).timeout(5000); // Timeout must be long enough for all the file I/O;

it('pre-built esm bundles are identical to the source', async () => {
const { default: bundled } = await import(prebuiltJsPath);
const regular = require('..');
const bundled = require(prebuiltPath);
assert.deepEqual(regular, bundled);
}).timeout(5000); // Timeout must be long enough for all the file I/O;
}).timeout(5000); // Timeout must be long enough for all the file I/O
});