diff --git a/packages/babel-plugin-transform-runtime/src/index.js b/packages/babel-plugin-transform-runtime/src/index.js index a9d0fd350deb..448d46f449c9 100644 --- a/packages/babel-plugin-transform-runtime/src/index.js +++ b/packages/babel-plugin-transform-runtime/src/index.js @@ -10,9 +10,9 @@ import { typeAnnotationToString } from "./helpers"; function resolveAbsoluteRuntime(moduleName: string, dirname: string) { try { - return path.dirname( - resolve.sync(`${moduleName}/package.json`, { basedir: dirname }), - ); + return path + .dirname(resolve.sync(`${moduleName}/package.json`, { basedir: dirname })) + .replace(/\\/g, "/"); } catch (err) { if (err.code !== "MODULE_NOT_FOUND") throw err; diff --git a/packages/babel-plugin-transform-runtime/test/fixtures/windows/absoluteRuntime/input.js b/packages/babel-plugin-transform-runtime/test/fixtures/windows/absoluteRuntime/input.js new file mode 100644 index 000000000000..42f8907ec4c7 --- /dev/null +++ b/packages/babel-plugin-transform-runtime/test/fixtures/windows/absoluteRuntime/input.js @@ -0,0 +1,9 @@ +async function test () { + console.log('test') +} + +async function main () { + console.log(await test()) +} + +main() diff --git a/packages/babel-plugin-transform-runtime/test/fixtures/windows/absoluteRuntime/options.json b/packages/babel-plugin-transform-runtime/test/fixtures/windows/absoluteRuntime/options.json new file mode 100644 index 000000000000..de2d6991e33e --- /dev/null +++ b/packages/babel-plugin-transform-runtime/test/fixtures/windows/absoluteRuntime/options.json @@ -0,0 +1,23 @@ +{ + "presets": [ + [ + "@babel/preset-env", + { + "corejs": 3, + "useBuiltIns": "entry" + } + ] + ], + "plugins": [ + [ + "transform-runtime", + { + "regenerator": false, + "corejs": false, + "helpers": true, + "useESModules": true, + "absoluteRuntime": true + } + ] + ] +} diff --git a/packages/babel-plugin-transform-runtime/test/fixtures/windows/absoluteRuntime/output.js b/packages/babel-plugin-transform-runtime/test/fixtures/windows/absoluteRuntime/output.js new file mode 100644 index 000000000000..323f1271c204 --- /dev/null +++ b/packages/babel-plugin-transform-runtime/test/fixtures/windows/absoluteRuntime/output.js @@ -0,0 +1,54 @@ +var _asyncToGenerator = require("/packages/babel-plugin-transform-runtime/node_modules/@babel/runtime/helpers/asyncToGenerator"); + +function test() { + return _test.apply(this, arguments); +} + +function _test() { + _test = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { + return regeneratorRuntime.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + console.log('test'); + + case 1: + case "end": + return _context.stop(); + } + } + }, _callee); + })); + return _test.apply(this, arguments); +} + +function main() { + return _main.apply(this, arguments); +} + +function _main() { + _main = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() { + return regeneratorRuntime.wrap(function _callee2$(_context2) { + while (1) { + switch (_context2.prev = _context2.next) { + case 0: + _context2.t0 = console; + _context2.next = 3; + return test(); + + case 3: + _context2.t1 = _context2.sent; + + _context2.t0.log.call(_context2.t0, _context2.t1); + + case 5: + case "end": + return _context2.stop(); + } + } + }, _callee2); + })); + return _main.apply(this, arguments); +} + +main(); diff --git a/packages/babel-plugin-transform-runtime/test/fixtures/windows/options.json b/packages/babel-plugin-transform-runtime/test/fixtures/windows/options.json new file mode 100644 index 000000000000..2163a20634fe --- /dev/null +++ b/packages/babel-plugin-transform-runtime/test/fixtures/windows/options.json @@ -0,0 +1,3 @@ +{ + "os": ["win32"] +}