Skip to content

Commit 07fd453

Browse files
authored
Merge pull request #67 from atom-community/babel7
2 parents 6845603 + a241502 commit 07fd453

File tree

10 files changed

+3726
-877
lines changed

10 files changed

+3726
-877
lines changed

package-lock.json

Lines changed: 3679 additions & 847 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
"@atom/nsfw": "^1.0.28",
1919
"@atom/source-map-support": "^0.3.4",
2020
"@atom/watcher": "^1.3.5",
21+
"@babel/core": "7.18.6",
22+
"babel-preset-atomic": "^5.0.0",
2123
"about": "file:packages/about",
2224
"archive-view": "https://www.atom.io/api/packages/archive-view/versions/0.66.0/tarball",
2325
"async": "3.2.0",
@@ -34,7 +36,6 @@
3436
"autocomplete-snippets": "https://www.atom.io/api/packages/autocomplete-snippets/versions/1.12.1/tarball",
3537
"autoflow": "file:packages/autoflow",
3638
"autosave": "https://www.atom.io/api/packages/autosave/versions/0.24.6/tarball",
37-
"babel-core": "5.8.38",
3839
"background-tips": "https://www.atom.io/api/packages/background-tips/versions/0.28.0/tarball",
3940
"base16-tomorrow-dark-theme": "file:packages/base16-tomorrow-dark-theme",
4041
"base16-tomorrow-light-theme": "file:packages/base16-tomorrow-light-theme",

packages/welcome/lib/guide-view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @babel */
2-
/** @jsx etch.dom **/
2+
/** @jsx etch.dom */
33

44
import etch from 'etch';
55

packages/welcome/lib/welcome-view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @babel */
2-
/** @jsx etch.dom **/
2+
/** @jsx etch.dom */
33

44
import etch from 'etch';
55

script/lib/generate-startup-snapshot.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,14 @@ module.exports = function(packagedAppPath) {
132132
'lib',
133133
'command-event.js'
134134
) ||
135-
requiredModuleRelativePath ===
136-
path.join('..', 'node_modules', 'babel-core', 'index.js') ||
135+
(requiredModuleRelativePath.includes('@babel') &&
136+
// GitHub package uses this in its relay dependency which is required on startup
137+
!requiredModuleRelativePath.includes(
138+
path.join('@babel', 'runtime')
139+
)) ||
140+
requiredModuleRelativePath.includes('babel-plugin') ||
141+
requiredModuleRelativePath.includes('babel-preset') ||
142+
requiredModuleRelativePath.includes('supports-color') ||
137143
requiredModuleRelativePath ===
138144
path.join('..', 'node_modules', 'debug', 'node.js') ||
139145
requiredModuleRelativePath ===

spec/compile-cache-spec.coffee

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
path = require 'path'
22
temp = require('temp').track()
3-
Babel = require 'babel-core'
3+
babelCompiler = require '../src/babel'
44
CoffeeScript = require 'coffee-script'
55
{TypeScriptSimple} = require 'typescript-simple'
66
CSON = require 'season'
@@ -16,7 +16,7 @@ describe 'CompileCache', ->
1616
CSON.setCacheDir(null)
1717
CompileCache.resetCacheStats()
1818

19-
spyOn(Babel, 'transform').andReturn {code: 'the-babel-code'}
19+
spyOn(babelCompiler, 'compile')
2020
spyOn(CoffeeScript, 'compile').andReturn 'the-coffee-code'
2121
spyOn(TypeScriptSimple::, 'compile').andReturn 'the-typescript-code'
2222

@@ -36,11 +36,11 @@ describe 'CompileCache', ->
3636
it 'compiles the file with babel and caches it', ->
3737
CompileCache.addPathToCache(path.join(fixtures, 'babel', 'babel-comment.js'), atomHome)
3838
expect(CompileCache.getCacheStats()['.js']).toEqual {hits: 0, misses: 1}
39-
expect(Babel.transform.callCount).toBe 1
39+
expect(babelCompiler.compile.callCount).toBe 1
4040

4141
CompileCache.addPathToCache(path.join(fixtures, 'babel', 'babel-comment.js'), atomHome)
4242
expect(CompileCache.getCacheStats()['.js']).toEqual {hits: 1, misses: 1}
43-
expect(Babel.transform.callCount).toBe 1
43+
expect(babelCompiler.compile.callCount).toBe 1
4444

4545
describe 'when the given file is coffee-script', ->
4646
it 'compiles the file with coffee-script and caches it', ->

spec/update-process-env-spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/** @babel */
2+
'not strict';
23

34
import path from 'path';
45
import childProcess from 'child_process';

src/babel.config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
let presets = [
2+
[
3+
'babel-preset-atomic',
4+
{
5+
// transform ES modules to commonjs
6+
keepModules: false,
7+
// some of the packages use non-strict JavaScript in ES6 modules! We need to add this for now. Eventually, we should fix those packages and remove these:
8+
notStrictDirectiveTriggers: ['use babel'],
9+
notStrictCommentTriggers: ['@babel', '@flow', '* @babel', '* @flow']
10+
}
11+
]
12+
];
13+
14+
let plugins = [];
15+
16+
module.exports = {
17+
presets: presets,
18+
plugins: plugins,
19+
exclude: 'node_modules/**',
20+
sourceMap: 'inline'
21+
};

src/babel.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
const crypto = require('crypto');
44
const path = require('path');
5-
const defaultOptions = require('../static/babelrc.json');
5+
const defaultOptions = require('./babel.config.js');
6+
const configFile = path.join(__dirname, './babel.config.js');
67

78
let babel = null;
89
let babelVersionDirectory = null;
@@ -31,7 +32,7 @@ exports.shouldCompile = function(sourceCode) {
3132

3233
exports.getCachePath = function(sourceCode) {
3334
if (babelVersionDirectory == null) {
34-
const babelVersion = require('babel-core/package.json').version;
35+
const babelVersion = require('@babel/core/package.json').version;
3536
babelVersionDirectory = path.join(
3637
'js',
3738
'babel',
@@ -50,28 +51,22 @@ exports.getCachePath = function(sourceCode) {
5051

5152
exports.compile = function(sourceCode, filePath) {
5253
if (!babel) {
53-
babel = require('babel-core');
54-
const Logger = require('babel-core/lib/transformation/file/logger');
55-
const noop = function() {};
56-
Logger.prototype.debug = noop;
57-
Logger.prototype.verbose = noop;
54+
babel = require('@babel/core');
5855
}
59-
6056
if (process.platform === 'win32') {
6157
filePath = 'file:///' + path.resolve(filePath).replace(/\\/g, '/');
6258
}
6359

64-
const options = { filename: filePath };
65-
for (const key in defaultOptions) {
66-
options[key] = defaultOptions[key];
67-
}
68-
return babel.transform(sourceCode, options).code;
60+
return babel.transformSync(sourceCode, {
61+
filename: filePath,
62+
configFile
63+
}).code;
6964
};
7065

7166
function createVersionAndOptionsDigest(version, options) {
7267
return crypto
7368
.createHash('sha1')
74-
.update('babel-core', 'utf8')
69+
.update('@babel/core', 'utf8')
7570
.update('\0', 'utf8')
7671
.update(version, 'utf8')
7772
.update('\0', 'utf8')

static/babelrc.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)