File tree Expand file tree Collapse file tree 6 files changed +65
-61
lines changed
templates/configuration/babelrc Expand file tree Collapse file tree 6 files changed +65
-61
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import _debug from 'app/utils/debug';
44import parseConfigurations from 'common/templates/configuration/parse' ;
55import initializeErrorTransformers from 'sandbox-hooks/errors/transformers' ;
66import { inject , unmount } from 'sandbox-hooks/react-error-overlay/overlay' ;
7+ import { isBabel7 } from 'common/utils/is-babel-7' ;
78
89import getPreset from './eval' ;
910import Manager from './eval/manager' ;
@@ -27,8 +28,6 @@ import getDefinition from '../../../common/templates/index';
2728
2829import { showRunOnClick } from './status-screen/run-on-click' ;
2930
30- import { isBabel7 } from './eval/utils/is-babel-7' ;
31-
3231let initializedResizeListener = false ;
3332let manager : ?Manager = null ;
3433let actionsEnabled = false ;
Original file line number Diff line number Diff line change 1- import semver from 'semver ' ;
1+ import { isBabel7 } from 'common/utils/is-babel-7 ' ;
22
33import Preset from '../' ;
44
@@ -9,20 +9,6 @@ import rawTranspiler from '../../transpilers/raw';
99import svgrTranspiler from '../../transpilers/svgr' ;
1010import sassTranspiler from '../../transpilers/sass' ;
1111
12- export function isVersion2 ( dependencies ) {
13- const usedDeps = dependencies || { } ;
14- if ( usedDeps [ 'react-scripts' ] ) {
15- const reactScriptsVersion = usedDeps [ 'react-scripts' ] ;
16-
17- return (
18- / ^ [ a - z ] / . test ( reactScriptsVersion ) ||
19- semver . intersects ( reactScriptsVersion , '^2.0.0' )
20- ) ;
21- }
22-
23- return false ;
24- }
25-
2612export default function initialize ( ) {
2713 let v2Initialized = false ;
2814 const preset = new Preset (
@@ -35,7 +21,7 @@ export default function initialize() {
3521 const configurations = manager . configurations ;
3622
3723 if (
38- isVersion2 (
24+ isBabel7 (
3925 configurations &&
4026 configurations . package &&
4127 configurations . package . parsed &&
Original file line number Diff line number Diff line change 11// @flow
22import BabelWorker from 'worker-loader?publicPath=/&name=babel-transpiler.[hash:8].worker.js!./worker/index.js' ;
3+ import { isBabel7 } from 'common/utils/is-babel-7' ;
34
45import isESModule from '../../utils/is-es-module' ;
56import regexGetRequireStatements from './worker/simple-get-require-statements' ;
67import getBabelConfig from './babel-parser' ;
78import WorkerTranspiler from '../worker-transpiler' ;
89import { type LoaderContext } from '../../transpiled-module' ;
910import type { default as Manager } from '../../manager' ;
10- import { isBabel7 } from '../../utils/is-babel-7' ;
1111
1212import delay from '../../../utils/delay' ;
1313
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11// @flow
2+ import { isBabel7 } from 'common/utils/is-babel-7' ;
3+
24import type { ConfigurationFile } from '../types' ;
35
46const JSX_PRAGMA = {
@@ -16,6 +18,17 @@ const config: ConfigurationFile = {
1618 template : string ,
1719 resolveModule : ( path : string ) => ?{ code: string }
1820 ) => {
21+ let isV7 = false ;
22+
23+ try {
24+ const packageJSON = resolveModule ( '/package.json' ) ;
25+ const parsed = JSON . parse ( packageJSON . code || '' ) ;
26+
27+ isV7 = isBabel7 ( parsed . dependencies , parsed . devDependencies ) ;
28+ } catch ( e ) {
29+ console . error ( e ) ;
30+ }
31+
1932 if ( template === 'preact-cli' ) {
2033 return JSON . stringify (
2134 {
@@ -48,22 +61,12 @@ const config: ConfigurationFile = {
4861 *
4962 * Need to fix this ASAP and make vue-cli 3 a separate template.
5063 */
51- try {
52- const packageJSON = resolveModule ( '/ package . json ') ;
53- const parsed = JSON . parse ( packageJSON . code ) ;
54-
55- if (
56- parsed . devDependencies &&
57- parsed . devDependencies [ '@vue/cli-plugin-babel' ]
58- ) {
59- return JSON . stringify ( {
60- presets : [ '@vue/app' ] ,
61- } ) ;
62- }
63- } catch ( e ) {
64- console . error ( e ) ;
65- }
6664
65+ if ( isV7 ) {
66+ return JSON . stringify ( {
67+ presets : [ '@vue/app' ] ,
68+ } ) ;
69+ }
6770 return JSON . stringify (
6871 {
6972 presets : [
@@ -97,16 +100,18 @@ const config: ConfigurationFile = {
97100
98101 if ( template === 'parcel' ) {
99102 const presets = [ 'env' ] ;
100- const plugins = [
101- [
102- 'transform-runtime' ,
103- {
104- polyfill : false ,
105- regenerator : true ,
106- } ,
107- ] ,
108- 'transform-object-rest-spread' ,
109- ] ;
103+ const plugins = isV7
104+ ? [ ]
105+ : [
106+ [
107+ 'transform-runtime' ,
108+ {
109+ polyfill : false ,
110+ regenerator : true ,
111+ } ,
112+ ] ,
113+ 'transform-object-rest-spread' ,
114+ ] ;
110115
111116 const packageJSONModule = resolveModule ( '/package.json' ) ;
112117
Original file line number Diff line number Diff line change 1+ import semver from 'semver' ;
2+
3+ function isCRAVersion2 ( dependencies ) {
4+ const usedDeps = dependencies || { } ;
5+ if ( usedDeps [ 'react-scripts' ] ) {
6+ const reactScriptsVersion = usedDeps [ 'react-scripts' ] ;
7+
8+ return (
9+ / ^ [ a - z ] / . test ( reactScriptsVersion ) ||
10+ semver . intersects ( reactScriptsVersion , '^2.0.0' )
11+ ) ;
12+ }
13+
14+ return false ;
15+ }
16+
17+ export function isBabel7 ( dependencies = { } , devDependencies = { } ) {
18+ if ( devDependencies [ '@vue/cli-plugin-babel' ] ) {
19+ return true ;
20+ }
21+
22+ if ( devDependencies [ '@babel/core' ] ) {
23+ return true ;
24+ }
25+
26+ if ( isCRAVersion2 ( dependencies ) ) {
27+ return true ;
28+ }
29+
30+ return false ;
31+ }
You can’t perform that action at this time.
0 commit comments