Skip to content

Commit e65b882

Browse files
James Zetlendevpatil7
James Zetlen
authored andcommitted
feat: remove esm mid-compilation and add babel preset (magento#1404)
* feat: remove esm mid-compilation and add babel preset * fixup babel circular dep * chore: update zeit to node 10 * fixup venia calls buildpack by path * refactor: remove buildpack build * fixup remove CI cache rule * fixup exclude babel preset in babel build * Update pwa-devdocs/scripts/create-reference-docs/config/peregrine/index.js Co-Authored-By: James Calcaben <[email protected]> * fixup now deploy new upward file * fix: fix now.json to a version
1 parent 98eb578 commit e65b882

File tree

182 files changed

+303
-651
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+303
-651
lines changed

.eslintignore

-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@
22
__fixtures__
33
# Minified build assets
44
dist
5-
# Babelified ES modules for NPM dependents
6-
esm
75
# Devdocs is a separate project
86
pwa-devdocs

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ lerna-debug.log
1414
.env
1515
yarn-error.log
1616
# Packages that build partially transpiled ES modules put them here
17-
packages/*/esm/*
1817
docker/certs

.nowignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
node_modules
22
dist
33
coverage
4-
esm
54
pwa-devdocs
65
storybook*
76
__test*

.prettierignore

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ coverage
33
# Minified build assets
44
dist
55
storybook-dist
6-
# Babelified ES modules for NPM dependents
7-
esm
86
# Devdocs is a separate project
97
pwa-devdocs
108

Dockerfile.dev

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ RUN apk --no-cache --virtual add \
1111
python \
1212
make \
1313
g++ \
14-
yarn
14+
yarn
1515

1616
# copy just the dependency files and configs needed for install
17+
COPY packages/babel-preset-peregrine/package.json ./packages/babel-preset-peregrine/package.json
18+
COPY packages/graphql-cli-validate-magento-pwa-queries/package.json ./packages/graphql-cli-validate-magento-pwa-queries/package.json
1719
COPY packages/peregrine/package.json ./packages/peregrine/package.json
1820
COPY packages/pwa-buildpack/package.json ./packages/pwa-buildpack/package.json
1921
COPY packages/upward-js/package.json ./packages/upward-js/package.json
2022
COPY packages/upward-spec/package.json ./packages/upward-spec/package.json
2123
COPY packages/venia-concept/package.json ./packages/venia-concept/package.json
22-
COPY package.json yarn.lock babel.config.js browserslist.js magento-compatibility.js ./
24+
COPY package.json yarn.lock babel.config.js magento-compatibility.js ./
2325

2426
# install dependencies with yarn
2527
RUN yarn install --frozen-lockfile
@@ -36,7 +38,7 @@ COPY ${ENVFILEPATH} ./packages/venia-concept/.env
3638
RUN yarn install --frozen-lockfile
3739

3840
# build the app
39-
RUN yarn run build
41+
RUN yarn run build
4042

4143
# MULTI-STAGE BUILD
4244
FROM node:10.14.1-alpine

Dockerfile.prod

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ RUN apk --no-cache --virtual add \
1010
yarn
1111

1212
# copy just the dependency files and configs needed for install
13+
COPY packages/babel-preset-peregrine/package.json ./packages/babel-preset-peregrine/package.json
14+
COPY packages/graphql-cli-validate-magento-pwa-queries/package.json ./packages/graphql-cli-validate-magento-pwa-queries/package.json
1315
COPY packages/peregrine/package.json ./packages/peregrine/package.json
1416
COPY packages/pwa-buildpack/package.json ./packages/pwa-buildpack/package.json
1517
COPY packages/upward-js/package.json ./packages/upward-js/package.json
1618
COPY packages/upward-spec/package.json ./packages/upward-spec/package.json
1719
COPY packages/venia-concept/package.json ./packages/venia-concept/package.json
18-
COPY package.json yarn.lock babel.config.js browserslist.js magento-compatibility.js ./
20+
COPY package.json yarn.lock babel.config.js magento-compatibility.js ./
1921

2022
# install dependencies with yarn
2123
RUN yarn install --frozen-lockfile

babel.config.js

+9-94
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,11 @@
1-
const browsers = require('./browserslist');
2-
const plugins = [
3-
['@babel/plugin-proposal-class-properties'],
4-
['@babel/plugin-proposal-object-rest-spread'],
5-
['@babel/plugin-syntax-dynamic-import'],
6-
['@babel/plugin-syntax-jsx'],
7-
['@babel/plugin-transform-react-jsx'],
8-
['babel-plugin-graphql-tag']
9-
];
10-
11-
const targets = {
12-
dev: 'last 2 Chrome versions',
13-
prod: browsers,
14-
test: 'node 10'
15-
};
16-
17-
const config = api => {
18-
const envConfigs = {
19-
/**
20-
* Watch mode and build:esm partial transpilation mode.
21-
* The module-resolver plugin makes Babel recognize import paths from
22-
* package root, like 'src/classify'.
23-
*
24-
* BUT VENIA SHOULD NOT USE THEM, because it makes Venia less portable
25-
* and Venia should be more portable than an average PWA Studio app.
26-
*/
27-
development: {
28-
// Ignore everything with underscores except stories
29-
ignore: [/\/__(tests?|mocks|fixtures|helpers|dist)__\//],
30-
plugins: [
31-
...plugins,
32-
[
33-
'module-resolver',
34-
{
35-
root: ['./'],
36-
/**
37-
* Exported modules will be consumed by other projects
38-
* which import Venia. Those projects will need to
39-
* override the 'src/drivers' dependency so Venia
40-
* modules will run outside the Venia app. This alias
41-
* exports the modules so the drivers dependency is
42-
* a unique string '@magento/venia-drivers', which is
43-
* less likely to collide with an existing dependency
44-
* than 'src/drivers' is.
45-
*
46-
* In webpack (or any build system) config for a project
47-
* using Venia modules, you must write an override for
48-
* '@magento/venia-drivers' and make an alias to that
49-
* module in your build configuration, e.g.:
50-
*
51-
* alias: {
52-
* '@magento/venia-drivers': './src/veniaDrivers'
53-
* }
54-
*
55-
* to map from this virtual string to your replacement.
56-
*/
57-
alias: {
58-
'^src/drivers$': '@magento/venia-drivers'
59-
},
60-
/**
61-
* Suppress console warning about missing dependencies.
62-
*/
63-
loglevel: 'silent'
64-
}
65-
]
66-
],
67-
presets: [
68-
['@babel/preset-env', { modules: false, targets: targets.dev }]
69-
]
70-
},
71-
production: {
72-
plugins: [
73-
...plugins,
74-
[
75-
'@babel/plugin-transform-runtime',
76-
{ helpers: true, regenerator: true }
77-
]
78-
],
79-
presets: [
80-
['@babel/preset-env', { modules: false, targets: targets.prod }]
81-
]
82-
},
83-
test: {
84-
plugins: [...plugins, ['babel-plugin-dynamic-import-node']],
85-
presets: [
86-
[
87-
'@babel/preset-env',
88-
{ modules: 'commonjs', targets: targets.test }
89-
]
90-
]
91-
}
1+
module.exports = api => {
2+
const config = {
3+
presets: ['@magento/peregrine'],
4+
exclude: [/packages\/babel\-preset\-peregrine\//]
925
};
93-
return envConfigs[api.env() || 'development'];
6+
if (api.env() === 'development') {
7+
// Ignore everything with underscores except stories in dev mode
8+
config.exclude.push(/\/__(tests?|mocks|fixtures|helpers|dist)__\//);
9+
}
10+
return config;
9411
};
95-
96-
module.exports = config;

docker-compose.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@ services:
2929
# this enables hot reloading from the container to detect changes made on the host file system
3030
volumes:
3131
- ./packages/peregrine/.storybook:/usr/src/app/packages/peregrine/.storybook:rw
32-
- ./packages/peregrine/esm:/usr/src/app/packages/peregrine/esm:rw
3332
- ./packages/peregrine/scripts:/usr/src/app/packages/peregrine/scripts:rw
34-
- ./packages/peregrine/src:/usr/src/app/packages/peregrine/src:rw
35-
- ./packages/pwa-buildpack/src:/usr/src/app/packages/pwa-buildpack/src:rw
33+
- ./packages/peregrine/lib:/usr/src/app/packages/peregrine/lib:rw
34+
- ./packages/pwa-buildpack/lib:/usr/src/app/packages/pwa-buildpack/lib:rw
3635
- ./packages/upward-js/lib:/usr/src/app/packages/upward-js/lib:rw
3736
- ./packages/venia-concept/.storybook:/usr/src/app/packages/venia-concept/.storybook:rw
38-
- ./packages/venia-concept/esm:/usr/src/app/packages/venia-concept/esm:rw
3937
- ./packages/venia-concept/src:/usr/src/app/packages/venia-concept/src:rw
4038
- ./packages/venia-concept/static:/usr/src/app/packages/venia-concept/static:rw
4139
links:

jest.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ const jestConfig = {
163163
// Don't look for test files in these directories.
164164
testPathIgnorePatterns: [
165165
'dist',
166-
'esm',
167166
'node_modules',
168167
'__fixtures__',
169168
'__helpers__',

now.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
"includeFiles": [
2727
"package.json",
2828
".env",
29-
"venia-upward.yml",
29+
"upward.yml",
3030
"static/*",
3131
"templates/*"
3232
],
3333
"maxLambdaSize": "20mb"
3434
},
3535
"src": "packages/venia-concept/server-lambda.js",
36-
"use": "@now/node"
36+
"use": "@now/node@0.11.1"
3737
}
3838
],
3939
"routes": [

package.json

+7-12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "3.0.0",
44
"private": true,
55
"workspaces": [
6+
"packages/babel-preset-peregrine",
67
"packages/graphql-cli-validate-magento-pwa-queries",
78
"packages/peregrine",
89
"packages/pwa-buildpack",
@@ -17,15 +18,13 @@
1718
"url": "https://github.com/magento-research/pwa-studio/issues"
1819
},
1920
"scripts": {
20-
"build": "yarn workspaces run build",
21-
"build:ci": "yarn workspaces run build:ci",
22-
"build:dev": "yarn workspaces run build:dev",
23-
"clean:all": "yarn workspaces run clean && rimraf ./node_modules",
21+
"build": "yarn workspace @magento/venia-concept run build",
22+
"clean:all": "yarn workspaces run -s clean && rimraf ./node_modules",
2423
"clean:dist": "yarn workspaces run clean",
2524
"coveralls": "cat ./coverage/lcov.info | coveralls",
2625
"danger": "danger-ci",
2726
"lint": "eslint '@(packages|scripts)/**/{*.js,package.json}' --ignore-pattern node_modules --ignore-pattern storybook-dist",
28-
"postbuild": "rimraf \"./packages/*/{esm,dist}/{,**/}__*__\"",
27+
"postbuild": "rimraf \"./packages/*/dist/{,**/}__*__\"",
2928
"prettier": "prettier --write '@(packages|scripts)/**/*.@(js|css)' '*.js'",
3029
"prettier:validate": "prettier-check '@(packages|scripts)/**/*.@(js|css)' '*.js'",
3130
"prettier:check": "prettier --list-different '@(packages|scripts)/**/*.@(js|css)' '*.js'",
@@ -38,14 +37,12 @@
3837
"test:dev": "jest --watch",
3938
"validate-queries": "yarn workspace @magento/venia-concept run validate-queries",
4039
"watch:all": "node scripts/watch-all.js",
41-
"watch:buildpack": "yarn workspace @magento/pwa-buildpack run watch; cd - >/dev/null",
42-
"watch:peregrine": "yarn workspace @magento/peregrine run watch; cd - >/dev/null",
4340
"watch:venia": "yarn workspace @magento/venia-concept run watch; cd - >/dev/null"
4441
},
4542
"devDependencies": {
43+
"@magento/babel-preset-peregrine": "~2.1.0",
4644
"@magento/eslint-config": "~1.4.1",
4745
"babel-eslint": "~10.0.1",
48-
"babel-plugin-module-resolver": "~3.2.0",
4946
"chalk": "~2.4.2",
5047
"chokidar": "~2.1.2",
5148
"concurrently": "^4.1.0",
@@ -66,21 +63,19 @@
6663
"jest-fetch-mock": "~2.1.1",
6764
"jest-junit": "~6.3.0",
6865
"jest-transform-graphql": "~2.1.0",
69-
"keypress": "~0.2.1",
7066
"lerna": "~3.13.0",
7167
"lodash.debounce": "~4.0.8",
72-
"multispinner": "~0.2.1",
7368
"prettier": "~1.16.4",
7469
"prettier-check": "~2.0.0",
75-
"stream-snitch": "~0.0.3",
70+
"rimraf": "~2.6.3",
7671
"wait-for-expect": "~1.1.0"
7772
},
7873
"optionalDependencies": {
7974
"bundlesize": "~0.17.1",
8075
"sharp": "~0.22.1"
8176
},
8277
"engines": {
83-
"node": "8.10.0 || >=10.7.0",
78+
"node": "10.x",
8479
"yarn": ">=1.12.0"
8580
},
8681
"husky": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Documentation for Magento PWA Studio packages is located at [https://pwastudio.io](https://pwastudio.io).
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const plugin = require('./lib/index.js');
2+
3+
module.exports = plugin;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const preset = require('../');
2+
3+
const babelConfigApi = {
4+
env: jest.fn().mockName('api.env')
5+
};
6+
7+
const findBabelModule = (list, module) =>
8+
list.find(item => {
9+
const moduleName = Array.isArray(item) ? item[0] : item;
10+
return moduleName === module;
11+
});
12+
13+
const pluginsAndPresets = {
14+
plugins: [],
15+
presets: []
16+
};
17+
18+
beforeEach(() => babelConfigApi.env.mockReset());
19+
20+
test('returns dev config if api.env() returns nil', () => {
21+
babelConfigApi.mockReturnValueOnce(undefined);
22+
expect(config).toMatchObject(pluginsAndPresets);
23+
expect(findBabelModule(config.presets, '@babel/preset-env')).toBeTruthy();
24+
expect(babelConfigApi.env).toHaveBeenCalled();
25+
});
26+
27+
test('returns dev config if api.env() returns "development"', () => {
28+
babelConfigApi.mockReturnValueOnce('development');
29+
expect(config).toMatchObject(pluginsAndPresets);
30+
expect(findBabelModule(config.presets, '@babel/preset-env')).toBeTruthy();
31+
expect(babelConfigApi.env).toHaveBeenCalled();
32+
});
33+
34+
test('accepts options', () => {
35+
babelConfigApi.mockReturnValueOnce(undefined);
36+
const config = preset(babelConfigApi, {
37+
targets: {
38+
dev: 'Nokia WAP'
39+
}
40+
});
41+
const presetEnv = findBabelModule(config.presets, '@babel/preset-env');
42+
expect(presetEnv[1].targets).toBe('Nokia WAP');
43+
expect(babelConfigApi.env).toHaveBeenCalled();
44+
});
45+
46+
test('returns test config if api.env() returns "test"', () => {
47+
babelConfigApi.mockReturnValueOnce('test');
48+
expect(config).toMatchObject(pluginsAndPresets);
49+
expect(
50+
findBabelModule(config.plugins, 'babel-plugin-dynamic-import-node')
51+
).toBeTruthy();
52+
expect(babelConfigApi.env).toHaveBeenCalled();
53+
});
54+
55+
test('returns production config if api.env() returns "production"', () => {
56+
babelConfigApi.mockReturnValueOnce('production');
57+
const config = preset(babelConfigApi);
58+
expect(config).toMatchObject(pluginsAndPresets);
59+
expect(
60+
findBabelModule(config.plugins, '@babel/plugin-transform-runtime')
61+
).toBeTruthy();
62+
expect(findBabelModule(config.presets, '@babel/preset-env')).toBeTruthy();
63+
expect(babelConfigApi.env).toHaveBeenCalled();
64+
});
File renamed without changes.

0 commit comments

Comments
 (0)