Skip to content

Commit

Permalink
Remove all usages of babel-node
Browse files Browse the repository at this point in the history
That extra transpile step means an extra dependency but doesn't add
any value
  • Loading branch information
BPScott committed Jan 8, 2019
1 parent 18a9ea9 commit 98183e0
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 146 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

28 changes: 14 additions & 14 deletions config/rollup/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import {resolve} from 'path';
import {readJSONSync} from 'fs-extra';
import nodeResolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import json from 'rollup-plugin-json';
import commonjs from 'rollup-plugin-commonjs';
const {resolve} = require('path');
const {readJSONSync} = require('fs-extra');
const nodeResolve = require('rollup-plugin-node-resolve');
const babel = require('rollup-plugin-babel');
const json = require('rollup-plugin-json');
const commonjs = require('rollup-plugin-commonjs');

import {dependencies, peerDependencies} from '../../package.json';
const {dependencies, peerDependencies} = require('../../package.json');

import styles from './plugins/styles';
import image from './plugins/image';
import icon from './plugins/icon';
const styles = require('./plugins/styles');
const image = require('./plugins/image');
const icon = require('./plugins/icon');

import getNamespacedClassName from './namespaced-classname';
import createExistingClassnameTokenUser from './use-existing-classname-tokens';
const getNamespacedClassName = require('./namespaced-classname');
const createExistingClassnameTokenUser = require('./use-existing-classname-tokens');

const project = resolve(__dirname, '../..');
const buildRoot = resolve(project, './build-intermediate');
Expand All @@ -27,7 +27,7 @@ const sassResources = [
resolve(styleRoot, './shared.scss'),
];

export default function createRollupConfig({
module.exports = function createRollupConfig({
entry,
writeCSS,
cssPath,
Expand Down Expand Up @@ -78,4 +78,4 @@ export default function createRollupConfig({
}),
],
};
}
};
8 changes: 4 additions & 4 deletions config/rollup/namespaced-classname.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {basename} from 'path';
import {camelCase} from 'change-case';
const {basename} = require('path');
const {camelCase} = require('change-case');

const cache = {
files: {},
Expand All @@ -9,7 +9,7 @@ const COMPONENT_REGEX = /^[A-Z]\w+$/;
const SUBCOMPONENT_VARIATION_SELECTOR = /^\w+-\w+$/;
const NESTED_COMPONENT_PATH_REGEX = /.*\/components\/(.*)\/components/;

export default function getNamespacedClassName(localName, filePath) {
module.exports = function getNamespacedClassName(localName, filePath) {
const file = cache.files[filePath] || {};
const componentName = basename(filePath, '.scss');
const nestedComponentMatch = NESTED_COMPONENT_PATH_REGEX.exec(filePath);
Expand Down Expand Up @@ -45,7 +45,7 @@ export default function getNamespacedClassName(localName, filePath) {
file[localName] = className;
cache.files[filePath] = file;
return className;
}
};

function isComponent(className) {
return COMPONENT_REGEX.test(className);
Expand Down
12 changes: 6 additions & 6 deletions config/rollup/plugins/icon.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {extname} from 'path';
import {createFilter} from 'rollup-pluginutils';
import SVGO from 'svgo';
const {extname} = require('path');
const {createFilter} = require('rollup-pluginutils');
const SVGO = require('svgo');

import {svgOptions} from '@shopify/images/optimize';
const {svgOptions} = require('@shopify/images/optimize');

const VIEWBOX_REGEX = /viewBox="([^"]*)"/;
const SVG_REGEX = /(<svg[^>]*>|<\/svg>)/g;
const FILL_REGEX = /fill="[^"]*"/g;

const svgo = new SVGO(svgOptions());

export default function icon(options = {}) {
module.exports = function icon(options = {}) {
const filter = createFilter(options.include, options.exclude);

return {
Expand Down Expand Up @@ -41,4 +41,4 @@ export default function icon(options = {}) {
});
},
};
}
};
10 changes: 5 additions & 5 deletions config/rollup/plugins/image.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {readFileSync} from 'fs';
import {extname} from 'path';
import {createFilter} from 'rollup-pluginutils';
const {readFileSync} = require('fs');
const {extname} = require('path');
const {createFilter} = require('rollup-pluginutils');

const MIME_TYPES = {
'.jpg': 'image/jpeg',
Expand All @@ -10,7 +10,7 @@ const MIME_TYPES = {
'.svg': 'image/svg+xml',
};

export default function image(options = {}) {
module.exports = function image(options = {}) {
const filter = createFilter(options.include, options.exclude);

return {
Expand All @@ -30,4 +30,4 @@ export default function image(options = {}) {
return `export default 'data:${mime};base64,${data}';`;
},
};
}
};
34 changes: 17 additions & 17 deletions config/rollup/plugins/styles.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import {resolve as resolvePath, dirname} from 'path';
import postcss from 'postcss';
import {readFileSync, ensureDirSync, writeFile} from 'fs-extra';
import {render} from 'node-sass';
import {createFilter} from 'rollup-pluginutils';
import cssnano from 'cssnano';

import cssModulesExtractImports from 'postcss-modules-extract-imports';
import cssModulesLocalByDefault from 'postcss-modules-local-by-default';
import cssModulesScope from 'postcss-modules-scope';
import cssModulesValues from 'postcss-modules-values';
import Parser from 'postcss-modules-parser';
import postcssShopify from 'postcss-shopify';
import genericNames from 'generic-names';

export default function styles(options = {}) {
const {resolve: resolvePath, dirname} = require('path');
const postcss = require('postcss');
const {readFileSync, ensureDirSync, writeFile} = require('fs-extra');
const {render} = require('node-sass');
const {createFilter} = require('rollup-pluginutils');
const cssnano = require('cssnano');

const cssModulesExtractImports = require('postcss-modules-extract-imports');
const cssModulesLocalByDefault = require('postcss-modules-local-by-default');
const cssModulesScope = require('postcss-modules-scope');
const cssModulesValues = require('postcss-modules-values');
const Parser = require('postcss-modules-parser');
const postcssShopify = require('postcss-shopify');
const genericNames = require('generic-names');

module.exports = function styles(options = {}) {
const filter = createFilter(
options.include || ['**/*.css', '**/*.scss'],
options.exclude,
Expand Down Expand Up @@ -127,7 +127,7 @@ export default function styles(options = {}) {
]);
},
};
}
};

function write(file, content) {
return new Promise((resolve, reject) => {
Expand Down
4 changes: 2 additions & 2 deletions config/rollup/use-existing-classname-tokens.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default function createExistingClassnameTokensUser(tokens) {
module.exports = function createExistingClassnameTokensUser(tokens) {
return function useExistingClassnameTokens(localName, filePath) {
return tokens[filePath][localName];
};
}
};
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@
"clean:build": "rimraf \"build/!(cache|coverage)\" build-esnext esnext styles types docs \"build-intermediate\" \"index.*\" \"./src/styles/polaris-tokens\" \"styles.{css,scss}\"",
"optimize": "node ./scripts/optimize.js",
"prebuild": "npm-run-all clean:build optimize copy-polaris-tokens",
"build": "babel-node ./scripts/build.js",
"build": "node ./scripts/build.js",
"prebuild-consumer": "yarn run build",
"build-consumer": "babel-node ./scripts/build-consumer",
"build-consumer": "node ./scripts/build-consumer",
"build-shrink-ray": "yarn run copy-polaris-tokens && node ./scripts/build-shrink-ray.js",
"secrets": "ejson decrypt -o secrets.json secrets.ejson",
"precdn": "yarn run build",
"cdn:deploy": "node ./scripts/deploy.js",
"cdn": "npm-run-all secrets cdn:deploy",
"preopen-styleguide-pr": "rimraf sandbox && yarn run secrets",
"open-styleguide-pr": "babel-node ./scripts/open-styleguide-pr",
"open-styleguide-pr": "node ./scripts/open-styleguide-pr",
"copy-polaris-tokens": "rimraf ./src/styles/polaris-tokens && shx cp -r ./node_modules/@shopify/polaris-tokens/dist ./src/styles/polaris-tokens",
"prepublish": "in-publish && yarn run build || :",
"postpublish": "in-publish && npm-run-all cdn open-styleguide-pr || :",
Expand All @@ -60,7 +60,7 @@
"test:a11y": "yarn run storybook:build && node ./scripts/pa11y.js",
"start": "start-storybook -p ${PORT} --ci --quiet",
"heroku-postbuild": "yarn run copy-polaris-tokens",
"readme-update-version": "babel-node ./scripts/readme-update-version",
"readme-update-version": "node ./scripts/readme-update-version",
"version": "yarn run readme-update-version",
"storybook": "start-storybook -p 6006 --quiet",
"storybook:build": "yarn run copy-polaris-tokens && build-storybook -o build/storybook/static"
Expand Down Expand Up @@ -101,7 +101,6 @@
"@types/rollup": "0.51.4",
"archiver": "^2.1.0",
"aws-sdk": "^2.58.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-preset-shopify": "^16.2.0",
Expand Down
6 changes: 3 additions & 3 deletions scripts/build-consumer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable no-console */

import {resolve} from 'path';
import {cp, mkdir, rm} from 'shelljs';
const {resolve} = require('path');
const {cp, mkdir, rm} = require('shelljs');

import packageJSON from '../package.json';
const packageJSON = require('../package.json');

const root = resolve(__dirname, '..');
const projectDir = process.argv[2];
Expand Down
18 changes: 9 additions & 9 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* eslint-disable no-console */

import {execSync} from 'child_process';
import {join, resolve as resolvePath} from 'path';
import {ensureDirSync, writeFileSync, readFileSync} from 'fs-extra';
import {rollup} from 'rollup';
import {cp, mv, rm} from 'shelljs';
import copyfiles from 'copyfiles';
const {execSync} = require('child_process');
const {join, resolve: resolvePath} = require('path');
const {ensureDirSync, writeFileSync, readFileSync} = require('fs-extra');
const {rollup} = require('rollup');
const {cp, mv, rm} = require('shelljs');
const copyfiles = require('copyfiles');

import createRollupConfig from '../config/rollup';
import packageJSON from '../package.json';
import generateSassBuild from './sass-build';
const createRollupConfig = require('../config/rollup');
const packageJSON = require('../package.json');
const generateSassBuild = require('./sass-build');

const root = resolvePath(__dirname, '..');
const build = resolvePath(root, 'build');
Expand Down
8 changes: 4 additions & 4 deletions scripts/open-styleguide-pr.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable no-console */

import {execSync} from 'child_process';
import {resolve} from 'path';
import {mkdir} from 'shelljs';
import semver from 'semver';
const {execSync} = require('child_process');
const {resolve} = require('path');
const {mkdir} = require('shelljs');
const semver = require('semver');

const {version: packageVersion} = require('../package.json');

Expand Down
16 changes: 8 additions & 8 deletions scripts/sass-build.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/* eslint-disable no-console */

import {basename, resolve, join, relative} from 'path';
import glob from 'glob';
import {
const {basename, resolve, join, relative} = require('path');
const glob = require('glob');
const {
writeFileSync,
readFileSync,
outputFileSync,
readJSONSync,
createWriteStream,
lstatSync,
existsSync,
} from 'fs-extra';
import {cp, mkdir} from 'shelljs';
import archiver from 'archiver';
} = require('fs-extra');
const {cp, mkdir} = require('shelljs');
const archiver = require('archiver');

const root = resolve(__dirname, '..');
const intermediateBuild = resolve(root, './build-intermediate');
const srcStyles = resolve(intermediateBuild, './styles');
const srcComponents = resolve(intermediateBuild, './components');

export default function generateSassBuild(destinationDir) {
module.exports = function generateSassBuild(destinationDir) {
const classnameTokens = readJSONSync(`${destinationDir}/polaris.tokens.json`);

const buildSass = resolve(destinationDir, 'sass');
Expand Down Expand Up @@ -97,7 +97,7 @@ export default function generateSassBuild(destinationDir) {
createSassIndex(components);

return generateSassZip(buildSass, destinationDir);
}
};

// see https://archiverjs.com/docs/
function generateSassZip(sourceDir, destinationDir) {
Expand Down
Loading

0 comments on commit 98183e0

Please sign in to comment.