Skip to content

Commit

Permalink
[core] Remove babel-node for server/shared modules (mui#15764)
Browse files Browse the repository at this point in the history
* Replace babel-node scripts with node

* Simplify imports

* Simplify imports

* Simplify imports

* Simplify imports

* Revert undecessary changes and docs:i18n script

* Poke codecov


Co-authored-by: Sebastian Silbermann <[email protected]>
  • Loading branch information
cvanem and eps1lon committed May 25, 2019
1 parent 9d4a0de commit 3f1bf78
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 56 deletions.
4 changes: 2 additions & 2 deletions docs/scripts/buildIcons.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */

import path from 'path';
import gm from 'gm';
const path = require('path');
const gm = require('gm');

const SIZES = [48, 70, 96, 150, 152, 192, 256, 310, 384, 512];
const INPUT_ICON = path.join(__dirname, '../../static/logo.png');
Expand Down
4 changes: 2 additions & 2 deletions docs/scripts/buildServiceWorker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */

import path from 'path';
import fse from 'fs-extra';
const path = require('path');
const fse = require('fs-extra');

async function prepend(file, string) {
const data = await fse.readFile(file, 'utf8');
Expand Down
15 changes: 11 additions & 4 deletions docs/src/modules/constants.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
export const CODE_VARIANTS = {
const CODE_VARIANTS = {
JS: 'JS',
TS: 'TS',
};

export const ACTION_TYPES = {
const ACTION_TYPES = {
THEME_CHANGE: 'THEME_CHANGE',
OPTIONS_CHANGE: 'OPTIONS_CHANGE',
};

// Active
export const LANGUAGES = ['en', 'zh', 'ru', 'pt', 'fr', 'es', 'de'];
const LANGUAGES = ['en', 'zh', 'ru', 'pt', 'fr', 'es', 'de'];

// Work in progress
export const LANGUAGES_IN_PROGRESS = ['en', 'zh', 'ru', 'pt', 'fr', 'es', 'de', 'ja'];
const LANGUAGES_IN_PROGRESS = ['en', 'zh', 'ru', 'pt', 'fr', 'es', 'de', 'ja'];

module.exports = {
CODE_VARIANTS,
ACTION_TYPES,
LANGUAGES,
LANGUAGES_IN_PROGRESS,
};
29 changes: 19 additions & 10 deletions docs/src/modules/utils/helpers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import warning from 'warning';
import upperFirst from 'lodash/upperFirst';
import camelCase from 'lodash/camelCase';
import { CODE_VARIANTS, LANGUAGES } from 'docs/src/modules/constants';
const warning = require('warning');
const upperFirst = require('lodash/upperFirst');
const camelCase = require('lodash/camelCase');
const { CODE_VARIANTS, LANGUAGES } = require('../constants');

export function titleize(string) {
function titleize(string) {
warning(
typeof string === 'string' && string.length > 0,
'titleize(string) expects a non empty string argument.',
Expand All @@ -15,7 +15,7 @@ export function titleize(string) {
.join(' ');
}

export function pageToTitle(page) {
function pageToTitle(page) {
if (page.title === false) {
return null;
}
Expand All @@ -34,7 +34,7 @@ export function pageToTitle(page) {
return titleize(name);
}

export function pageToTitleI18n(page, t) {
function pageToTitleI18n(page, t) {
const path = page.subheader || page.pathname;
return t(`pages.${path}`, { ignoreWarning: true }) || pageToTitle(page);
}
Expand Down Expand Up @@ -82,7 +82,7 @@ function addTypeDeps(deps) {
* @param {'next' | 'latest'} options.reactVersion
* @returns {Record<string, 'latest'>} map of packages with their required version
*/
export function getDependencies(raw, options = {}) {
function getDependencies(raw, options = {}) {
const { codeLanguage = CODE_VARIANTS.JS, reactVersion = 'latest' } = options;
const deps = {
'react-dom': reactVersion,
Expand Down Expand Up @@ -125,12 +125,12 @@ export function getDependencies(raw, options = {}) {
return deps;
}

export function getCookie(name) {
function getCookie(name) {
const regex = new RegExp(`(?:(?:^|.*;*)${name}*=*([^;]*).*$)|^.*$`);
return document.cookie.replace(regex, '$1');
}

export function pathnameToLanguage(pathname) {
function pathnameToLanguage(pathname) {
const userLanguage = pathname.substring(1, 3);

if (LANGUAGES.indexOf(userLanguage) !== -1 && pathname.indexOf(`/${userLanguage}/`) === 0) {
Expand All @@ -145,3 +145,12 @@ export function pathnameToLanguage(pathname) {
canonical: pathname,
};
}

module.exports = {
titleize,
pageToTitle,
pageToTitleI18n,
getDependencies,
getCookie,
pathnameToLanguage,
};
16 changes: 8 additions & 8 deletions docs/src/server.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import address from 'address';
import http from 'http';
import express from 'express';
import url from 'url';
import next from 'next';
import { addTeardown } from 'modules/handleKillSignals';
import { pathnameToLanguage } from 'docs/src/modules/utils/helpers';
import log from 'modules/log';
const address = require('address');
const http = require('http');
const express = require('express');
const url = require('url');
const next = require('next');
const { addTeardown } = require('../../modules/handleKillSignals');
const { pathnameToLanguage } = require('./modules/utils/helpers');
const log = require('../../modules/log');

const nextApp = next({
dev: process.env.NODE_ENV !== 'production',
Expand Down
18 changes: 12 additions & 6 deletions modules/handleKillSignals.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import log from 'modules/log';
const log = require('./log');

const SHUTDOWN_TIMEOUT = 10e3;

let shuttingDown = false;
const teardowns = [];

export function isShuttingDown() {
function isShuttingDown() {
return shuttingDown;
}

Expand All @@ -14,7 +14,7 @@ export function isShuttingDown() {
* Terminate server on receipt of the specified signal.
* @param {string} signal Signal to terminate on.
*/
export async function shutdown(signal, origin) {
async function shutdown(signal, origin) {
if (typeof signal === 'string') {
log.info({
name: 'kill signal',
Expand Down Expand Up @@ -54,11 +54,11 @@ export async function shutdown(signal, origin) {
process.exit(1);
}

export function addTeardown(teardown) {
function addTeardown(teardown) {
teardowns.push(teardown);
}

export function removeTeardown(teardown) {
function removeTeardown(teardown) {
const index = teardowns.indexOf(teardown);
teardowns.splice(index, 1);
}
Expand Down Expand Up @@ -103,4 +103,10 @@ function handleKillSignals() {
});
}

export default handleKillSignals;
module.exports = {
handleKillSignals,
isShuttingDown,
shutdown,
addTeardown,
removeTeardown,
};
4 changes: 2 additions & 2 deletions modules/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function fastAndSafeJsonStringify(object) {
}
}

export function logMethod(process, console, type) {
function logMethod(process, console, type) {
return object => {
const { name, msg, force = false } = object;
let formatedMsg = msg;
Expand Down Expand Up @@ -144,4 +144,4 @@ const log = {
fatal: logMethod(process, console, 'fatal'),
};

export default log;
module.exports = log;
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"argos": "argos upload test/regressions/screenshots/chrome --token $ARGOS_TOKEN",
"docs:api": "rimraf ./pages/api && cross-env BABEL_ENV=test babel-node ./docs/scripts/buildApi.js ./packages/material-ui/src ./pages/api && cross-env BABEL_ENV=test babel-node ./docs/scripts/buildApi.js ./packages/material-ui-lab/src ./pages/api",
"docs:build": "rimraf .next && cross-env NODE_ENV=production BABEL_ENV=docs-production next build",
"docs:build-sw": "babel-node ./docs/scripts/buildServiceWorker.js",
"docs:build-sw": "node ./docs/scripts/buildServiceWorker.js",
"docs:deploy": "git push material-ui-docs master:latest",
"docs:dev": "rimraf node_modules/.cache/babel-loader && cross-env BABEL_ENV=docs-development babel-node docs/src/server.js",
"docs:dev": "rimraf node_modules/.cache/babel-loader && cross-env BABEL_ENV=docs-development node docs/src/server.js",
"docs:export": "rimraf docs/export && next export -o docs/export && yarn docs:build-sw && cp -r docs/static/. docs/export",
"docs:icons": "rimraf static/icons/* && babel-node ./docs/scripts/buildIcons.js",
"docs:icons": "rimraf static/icons/* && node ./docs/scripts/buildIcons.js",
"docs:size-why": "cross-env DOCS_STATS_ENABLED=true yarn docs:build",
"docs:start": "next start",
"docs:i18n": "cross-env BABEL_ENV=test babel-node ./docs/scripts/i18n.js",
Expand All @@ -39,8 +39,8 @@
"lint": "eslint . --cache --report-unused-disable-directives",
"lint:ci": "eslint . --report-unused-disable-directives",
"lint:fix": "eslint . --cache --fix",
"prettier": "yarn babel-node ./scripts/prettier.js",
"prettier:all": "yarn babel-node ./scripts/prettier.js write",
"prettier": "yarn node ./scripts/prettier.js",
"prettier:all": "yarn node ./scripts/prettier.js write",
"size:snapshot": "node scripts/sizeSnapshot/create",
"size:why": "size-limit --why packages/material-ui/build/index.js",
"start": "yarn docs:dev",
Expand All @@ -49,7 +49,7 @@
"test:coverage:html": "cross-env NODE_ENV=test BABEL_ENV=coverage nyc mocha 'packages/**/**/*.test.js' --exclude '**/node_modules/**' && nyc report --reporter=html",
"test:karma": "cross-env NODE_ENV=test karma start test/karma.conf.js",
"test:regressions": "webpack --config test/regressions/webpack.config.js && rimraf test/regressions/screenshots/chrome/* && vrtest run --config test/vrtest.config.js --record",
"test:umd": "yarn babel-node packages/material-ui/test/umd/run.js",
"test:umd": "yarn node packages/material-ui/test/umd/run.js",
"test:unit": "cross-env NODE_ENV=test mocha 'packages/**/*.test.js' 'docs/**/*.test.js' --exclude '**/node_modules/**'",
"test:watch": "yarn test:unit --watch",
"typescript": "lerna run typescript && yarn docs:typescript:check"
Expand Down
16 changes: 8 additions & 8 deletions packages/material-ui/test/umd/run.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import puppeteer from 'puppeteer';
import fse from 'fs-extra';
import http from 'http';
import path from 'path';
import express from 'express';
import expect from 'expect-puppeteer';
import { addTeardown, shutdown } from 'modules/handleKillSignals';
import log from 'modules/log';
const puppeteer = require('puppeteer');
const fse = require('fs-extra');
const http = require('http');
const path = require('path');
const express = require('express');
const expect = require('expect-puppeteer');
const { addTeardown, shutdown } = require('../../../../modules/handleKillSignals');
const log = require('../../../../modules/log');

const port = 3090;
const host = '0.0.0.0';
Expand Down
6 changes: 3 additions & 3 deletions scripts/listChangedFiles.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Based on similar script in React
// https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/scripts/shared/listChangedFiles.js

import util from 'util';
import childProcess from 'child_process';
const util = require('util');
const childProcess = require('child_process');

const execFileAsync = util.promisify(childProcess.execFile);

Expand Down Expand Up @@ -33,4 +33,4 @@ async function listChangedFiles() {
return new Set([...gitDiff, ...gitLs]);
}

export default listChangedFiles;
module.exports = listChangedFiles;
10 changes: 5 additions & 5 deletions scripts/prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

// supported modes = check, check-changed, write, write-changed

import glob from 'glob-gitignore';
import prettier from 'prettier';
import fs from 'fs';
import path from 'path';
import listChangedFiles from './listChangedFiles';
const glob = require('glob-gitignore');
const prettier = require('prettier');
const fs = require('fs');
const path = require('path');
const listChangedFiles = require('./listChangedFiles');

const mode = process.argv[2] || 'write-changed';
const shouldWrite = mode === 'write' || mode === 'write-changed';
Expand Down

0 comments on commit 3f1bf78

Please sign in to comment.