-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove esm mid-compilation and add babel preset (#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 <jcalcaben@users.noreply.github.com> * fixup now deploy new upward file * fix: fix now.json to a version
- Loading branch information
1 parent
98eb578
commit e65b882
Showing
182 changed files
with
303 additions
and
651 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
node_modules | ||
dist | ||
coverage | ||
esm | ||
pwa-devdocs | ||
storybook* | ||
__test* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,11 @@ | ||
const browsers = require('./browserslist'); | ||
const plugins = [ | ||
['@babel/plugin-proposal-class-properties'], | ||
['@babel/plugin-proposal-object-rest-spread'], | ||
['@babel/plugin-syntax-dynamic-import'], | ||
['@babel/plugin-syntax-jsx'], | ||
['@babel/plugin-transform-react-jsx'], | ||
['babel-plugin-graphql-tag'] | ||
]; | ||
|
||
const targets = { | ||
dev: 'last 2 Chrome versions', | ||
prod: browsers, | ||
test: 'node 10' | ||
}; | ||
|
||
const config = api => { | ||
const envConfigs = { | ||
/** | ||
* Watch mode and build:esm partial transpilation mode. | ||
* The module-resolver plugin makes Babel recognize import paths from | ||
* package root, like 'src/classify'. | ||
* | ||
* BUT VENIA SHOULD NOT USE THEM, because it makes Venia less portable | ||
* and Venia should be more portable than an average PWA Studio app. | ||
*/ | ||
development: { | ||
// Ignore everything with underscores except stories | ||
ignore: [/\/__(tests?|mocks|fixtures|helpers|dist)__\//], | ||
plugins: [ | ||
...plugins, | ||
[ | ||
'module-resolver', | ||
{ | ||
root: ['./'], | ||
/** | ||
* Exported modules will be consumed by other projects | ||
* which import Venia. Those projects will need to | ||
* override the 'src/drivers' dependency so Venia | ||
* modules will run outside the Venia app. This alias | ||
* exports the modules so the drivers dependency is | ||
* a unique string '@magento/venia-drivers', which is | ||
* less likely to collide with an existing dependency | ||
* than 'src/drivers' is. | ||
* | ||
* In webpack (or any build system) config for a project | ||
* using Venia modules, you must write an override for | ||
* '@magento/venia-drivers' and make an alias to that | ||
* module in your build configuration, e.g.: | ||
* | ||
* alias: { | ||
* '@magento/venia-drivers': './src/veniaDrivers' | ||
* } | ||
* | ||
* to map from this virtual string to your replacement. | ||
*/ | ||
alias: { | ||
'^src/drivers$': '@magento/venia-drivers' | ||
}, | ||
/** | ||
* Suppress console warning about missing dependencies. | ||
*/ | ||
loglevel: 'silent' | ||
} | ||
] | ||
], | ||
presets: [ | ||
['@babel/preset-env', { modules: false, targets: targets.dev }] | ||
] | ||
}, | ||
production: { | ||
plugins: [ | ||
...plugins, | ||
[ | ||
'@babel/plugin-transform-runtime', | ||
{ helpers: true, regenerator: true } | ||
] | ||
], | ||
presets: [ | ||
['@babel/preset-env', { modules: false, targets: targets.prod }] | ||
] | ||
}, | ||
test: { | ||
plugins: [...plugins, ['babel-plugin-dynamic-import-node']], | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ modules: 'commonjs', targets: targets.test } | ||
] | ||
] | ||
} | ||
module.exports = api => { | ||
const config = { | ||
presets: ['@magento/peregrine'], | ||
exclude: [/packages\/babel\-preset\-peregrine\//] | ||
}; | ||
return envConfigs[api.env() || 'development']; | ||
if (api.env() === 'development') { | ||
// Ignore everything with underscores except stories in dev mode | ||
config.exclude.push(/\/__(tests?|mocks|fixtures|helpers|dist)__\//); | ||
} | ||
return config; | ||
}; | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Documentation for Magento PWA Studio packages is located at [https://pwastudio.io](https://pwastudio.io). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const plugin = require('./lib/index.js'); | ||
|
||
module.exports = plugin; |
64 changes: 64 additions & 0 deletions
64
packages/babel-preset-peregrine/lib/__tests__/index.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const preset = require('../'); | ||
|
||
const babelConfigApi = { | ||
env: jest.fn().mockName('api.env') | ||
}; | ||
|
||
const findBabelModule = (list, module) => | ||
list.find(item => { | ||
const moduleName = Array.isArray(item) ? item[0] : item; | ||
return moduleName === module; | ||
}); | ||
|
||
const pluginsAndPresets = { | ||
plugins: [], | ||
presets: [] | ||
}; | ||
|
||
beforeEach(() => babelConfigApi.env.mockReset()); | ||
|
||
test('returns dev config if api.env() returns nil', () => { | ||
babelConfigApi.mockReturnValueOnce(undefined); | ||
expect(config).toMatchObject(pluginsAndPresets); | ||
expect(findBabelModule(config.presets, '@babel/preset-env')).toBeTruthy(); | ||
expect(babelConfigApi.env).toHaveBeenCalled(); | ||
}); | ||
|
||
test('returns dev config if api.env() returns "development"', () => { | ||
babelConfigApi.mockReturnValueOnce('development'); | ||
expect(config).toMatchObject(pluginsAndPresets); | ||
expect(findBabelModule(config.presets, '@babel/preset-env')).toBeTruthy(); | ||
expect(babelConfigApi.env).toHaveBeenCalled(); | ||
}); | ||
|
||
test('accepts options', () => { | ||
babelConfigApi.mockReturnValueOnce(undefined); | ||
const config = preset(babelConfigApi, { | ||
targets: { | ||
dev: 'Nokia WAP' | ||
} | ||
}); | ||
const presetEnv = findBabelModule(config.presets, '@babel/preset-env'); | ||
expect(presetEnv[1].targets).toBe('Nokia WAP'); | ||
expect(babelConfigApi.env).toHaveBeenCalled(); | ||
}); | ||
|
||
test('returns test config if api.env() returns "test"', () => { | ||
babelConfigApi.mockReturnValueOnce('test'); | ||
expect(config).toMatchObject(pluginsAndPresets); | ||
expect( | ||
findBabelModule(config.plugins, 'babel-plugin-dynamic-import-node') | ||
).toBeTruthy(); | ||
expect(babelConfigApi.env).toHaveBeenCalled(); | ||
}); | ||
|
||
test('returns production config if api.env() returns "production"', () => { | ||
babelConfigApi.mockReturnValueOnce('production'); | ||
const config = preset(babelConfigApi); | ||
expect(config).toMatchObject(pluginsAndPresets); | ||
expect( | ||
findBabelModule(config.plugins, '@babel/plugin-transform-runtime') | ||
).toBeTruthy(); | ||
expect(findBabelModule(config.presets, '@babel/preset-env')).toBeTruthy(); | ||
expect(babelConfigApi.env).toHaveBeenCalled(); | ||
}); |
File renamed without changes.
Oops, something went wrong.
e65b882
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully aliased the URL https://venia-cj2wd9kyo.now.sh to the following aliases: