corejs-upgrade-webpack-plugin
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -22,6 +22,4 @@ "use strict"; | ||
const rewriteCoreJsRequest = originalRequest => { | ||
if (/core-js\/modules\/(.*)/.test(originalRequest)) { | ||
const modulesInformations = originalRequest.match(/core-js\/modules\/es(6|7)\.(.*)/); | ||
const esVersion = modulesInformations[1]; | ||
const originalPath = modulesInformations[2]; | ||
if (/core-js\/modules\/es(6|7)\.(.*)/.test(originalRequest)) { | ||
const [, esVersion, originalPath] = originalRequest.match(/core-js\/modules\/es(6|7)\.(.*)/); | ||
@@ -38,4 +36,3 @@ if (esVersion === '6') { | ||
if (/core-js\/library\/fn\/(.*)/.test(originalRequest)) { | ||
const modulesInformations = originalRequest.match(/core-js\/library\/fn\/(.*)/); | ||
const originalPath = modulesInformations[1]; | ||
const [, originalPath] = originalRequest.match(/core-js\/library\/fn\/(.*)/); | ||
return rewriteAndPreservePrefix(originalRequest, `features/${originalPath}`, 'core-js-pure'); | ||
@@ -45,5 +42,3 @@ } | ||
if (/core-js\/es(5|6|7)(.*)/.test(originalRequest)) { | ||
const modulesInformations = originalRequest.match(/core-js\/es(5|6|7)(.*)?/); | ||
const esVersion = modulesInformations[1]; | ||
const originalPath = modulesInformations[2]; | ||
const [, esVersion, originalPath] = originalRequest.match(/core-js\/es(5|6|7)(.*)?/); | ||
@@ -65,4 +60,3 @@ if (esVersion === '5') { | ||
if (/core-js\/(object)\/(.*)/.test(originalRequest)) { | ||
const modulesInformations = originalRequest.match(/core-js\/(.*)?/); | ||
const originalPath = modulesInformations[1]; | ||
const [, originalPath] = originalRequest.match(/core-js\/(.*)?/); | ||
return rewriteAndPreservePrefix(originalRequest, `features/${originalPath}`); | ||
@@ -69,0 +63,0 @@ } |
{ | ||
"name": "corejs-upgrade-webpack-plugin", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "a webpack plugin that transforms core-js v2 paths to core-js v3 paths", | ||
"keywords": [ | ||
"core-js", | ||
"webpack", | ||
"path", | ||
"resolve", | ||
"transform", | ||
"path", | ||
"resolve" | ||
"webpack" | ||
], | ||
@@ -16,4 +16,5 @@ "license": "MIT", | ||
"scripts": { | ||
"prepublish": "npm run build", | ||
"build": "babel src -d dist --extensions '.ts'", | ||
"generate-types": "tsc --emitDeclarationOnly --declaration src/index.ts --esModuleInterop --outDir dist", | ||
"prepublish": "npm run build && npm run generate-types", | ||
"test": "jest" | ||
@@ -32,4 +33,5 @@ }, | ||
"eslint": "^5.16.0", | ||
"jest": "^24.8.0" | ||
"jest": "^24.8.0", | ||
"typescript": "^3.5.1" | ||
} | ||
} |
import CoreJsAutoUpgradePlugin, { rewriteCoreJsRequest } from './index'; | ||
describe('CoreJsAutoUpgradePlugin', () => { | ||
it('should be constructable, without options', () => { | ||
expect(() => new CoreJsAutoUpgradePlugin()).not.toThrow() | ||
}); | ||
it('should be constructable, with options', () => { | ||
expect(() => new CoreJsAutoUpgradePlugin({ | ||
resolveFrom: __dirname, | ||
})).not.toThrow() | ||
}); | ||
}); | ||
describe('rewriteCoreJsRequest', () => { | ||
@@ -18,2 +29,14 @@ const fakeRequire = jest.mock(); | ||
}); | ||
it('should rewrite `core-js/modules/es.*` import to `core-js/modules/es.*`', () => { | ||
expect(rewriteCoreJsRequest('core-js/modules/es.object.is-frozen.js')).toBe( | ||
'core-js/modules/es.object.is-frozen.js' | ||
); | ||
}); | ||
it('should rewrite `core-js/modules/esnext.*` import to `core-js/modules/esnext.*`', () => { | ||
expect(rewriteCoreJsRequest('core-js/modules/esnext.set.some.js')).toBe( | ||
'core-js/modules/esnext.set.some.js' | ||
); | ||
}); | ||
}); | ||
@@ -20,0 +43,0 @@ |
@@ -12,6 +12,4 @@ import { NormalModuleReplacementPlugin } from 'webpack'; | ||
export const rewriteCoreJsRequest = (originalRequest: string) => { | ||
if (/core-js\/modules\/(.*)/.test(originalRequest)) { | ||
const modulesInformations = originalRequest.match(/core-js\/modules\/es(6|7)\.(.*)/); | ||
const esVersion = modulesInformations[1]; | ||
const originalPath = modulesInformations[2]; | ||
if (/core-js\/modules\/es(6|7)\.(.*)/.test(originalRequest)) { | ||
const [,esVersion, originalPath] = originalRequest.match(/core-js\/modules\/es(6|7)\.(.*)/); | ||
@@ -27,4 +25,3 @@ if (esVersion === '6') { | ||
if (/core-js\/library\/fn\/(.*)/.test(originalRequest)) { | ||
const modulesInformations = originalRequest.match(/core-js\/library\/fn\/(.*)/); | ||
const originalPath = modulesInformations[1]; | ||
const [,originalPath] = originalRequest.match(/core-js\/library\/fn\/(.*)/); | ||
@@ -35,5 +32,3 @@ return rewriteAndPreservePrefix(originalRequest, `features/${originalPath}`, 'core-js-pure'); | ||
if (/core-js\/es(5|6|7)(.*)/.test(originalRequest)) { | ||
const modulesInformations = originalRequest.match(/core-js\/es(5|6|7)(.*)?/); | ||
const esVersion = modulesInformations[1]; | ||
const originalPath = modulesInformations[2]; | ||
const [,esVersion, originalPath] = originalRequest.match(/core-js\/es(5|6|7)(.*)?/); | ||
@@ -54,4 +49,3 @@ if (esVersion === '5') { | ||
if (/core-js\/(object)\/(.*)/.test(originalRequest)) { | ||
const modulesInformations = originalRequest.match(/core-js\/(.*)?/); | ||
const originalPath = modulesInformations[1]; | ||
const [,originalPath] = originalRequest.match(/core-js\/(.*)?/); | ||
@@ -58,0 +52,0 @@ return rewriteAndPreservePrefix(originalRequest, `features/${originalPath}`); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11661
7
227
8