Skip to content

Commit 3cb3b73

Browse files
committed
Make mdn-data a pure build time dependency.
The mdn-data package is not being released to npm on any sort of regular basis. This change is preparing for the ability to update directly from the github repo using scripts or submodules. Also, it's best if all the data is in kept in sync because the mdn-data changes are not following any sort of semver concepts in how they land schema or data changes.
1 parent 1cb6911 commit 3cb3b73

9 files changed

+25
-10
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
"mocha": "^3.5.0",
4343
"pre-commit": "^1.2.2",
4444
"postcss-value-parser": "^3.3.0",
45-
"sinon": "^2.4.1"
45+
"sinon": "^2.4.1",
46+
"mdn-data": "1.0.0"
4647
},
4748
"dependencies": {
4849
"fs-extra": "^3.0.1",
49-
"mdn-data": "1.0.0",
5050
"moo": "^0.4.1",
5151
"nearley": "^2.11.0"
5252
}

src/expandShorthandProperty.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const nearley = require('nearley');
2-
const { css: { properties } } = require('mdn-data');
2+
const properties = require('../formatted-data/properties.json');
33
const isShorthandProperty = require('./isShorthandProperty');
44
const getShorthandComputedProperties = require('./getShorthandComputedProperties');
55
const shorthandProperties = require('../formatted-data/shorthand-properties.json');

src/getShorthandComputedProperties.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { css: { properties } } = require('mdn-data');
1+
const properties = require('../formatted-data/properties.json');
22

33
/**
44
* Given a shorthand property, returns an array of the computed properties for that shorthand property. If given

src/getShorthandsForProperty.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const shortHandProperties = require('../formatted-data/shorthand-properties.json');
2-
const { css: { properties } } = require('mdn-data');
2+
const properties = require('../formatted-data/properties.json');
33

44
/**
55
* @type {Object}

src/initialValueMap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { css: { properties } } = require('mdn-data');
1+
const properties = require('../formatted-data/properties.json');
22
const getShorthandComputedProperties = require('./getShorthandComputedProperties');
33
const isShorthandProperty = require('./isShorthandProperty');
44

src/isValidDeclaration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const nearley = require('nearley');
2-
const { css: { properties } } = require('mdn-data');
2+
const properties = require('../formatted-data/properties.json');
33
const { CSS } = require('./constants');
44

55
/**

src/scripts/extractProperties.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Takes raw data from MDN, filters out the shorthand properties, and decorates the data with additional properties.
3+
* Writes the formatted data to FORMATTED_DATA_PATH.
4+
*/
5+
const fs = require('fs-extra');
6+
const { css: { properties } } = require('mdn-data');
7+
const PATHS = require('../constants/paths');
8+
9+
const ALL_PROPERTIES_DATA_FILE_NAME = 'properties.json';
10+
const OUTPUT_FILE = `${PATHS.FORMATTED_DATA_PATH}${ALL_PROPERTIES_DATA_FILE_NAME}`;
11+
fs.writeJson(OUTPUT_FILE, properties, { spaces: 2 })
12+
.then(() => (
13+
console.log(`Successfully extracted properties to ${OUTPUT_FILE}`)
14+
));

test/InitialValuesTest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { assert } = require('chai');
2-
const { css: { properties: cssProperties } } = require('mdn-data');
2+
const properties = require('../formatted-data/properties.json');
33
const {
44
initialValue,
55
initialValues,
@@ -31,7 +31,7 @@ describe('Initial values', function () {
3131
'position',
3232
'transform-box',
3333
]);
34-
Object.keys(cssProperties).forEach((prop) => {
34+
Object.keys(properties).forEach((prop) => {
3535
if (prop.startsWith('-') || buggyValues.has(prop)) return; // bug in grammar data
3636
let initial = initialValue(prop);
3737
assert(isValidDeclaration(prop, initial), `${prop}: ${initial} is not a legal initial value`);

updateCSSData.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ node ./node_modules/nearley/bin/nearleyc.js ./src/grammars/nearley/formalSyntax.
1919
node ./src/scripts/updateBasicDataUnits.js || exit 1
2020
node ./src/scripts/formatData.js || exit 1
2121
node ./src/scripts/formatFormalSyntaxes.js || exit 1
22-
node ./src/scripts/formatGrammars.js || exit 1
22+
node ./src/scripts/formatGrammars.js || exit 1
23+
node ./src/scripts/extractProperties.js || exit 1

0 commit comments

Comments
 (0)