Remove packages
This commit is contained in:
parent
3d1c4ccc13
commit
7554556005
|
@ -1,38 +0,0 @@
|
|||
A [Babel](http://babeljs.io/) plugin that rewrites bare ES module specifiers as
|
||||
[unpkg](https://unpkg.com) URLs.
|
||||
|
||||
## input
|
||||
|
||||
```jsx
|
||||
import React from "react"
|
||||
import router from "@angular/router"
|
||||
import map from "lodash.map"
|
||||
import fs from "pn/fs"
|
||||
import cupcakes from "./cupcakes"
|
||||
import shoelaces from "/shoelaces"
|
||||
import something from "//something.com/whatevs"
|
||||
import something from "http://something.com/whatevs"
|
||||
let ReactDOM = require("react-dom")
|
||||
export React from "react"
|
||||
export { Component } from "react"
|
||||
export * from "react"
|
||||
export var message = "hello"
|
||||
```
|
||||
|
||||
## output
|
||||
|
||||
```jsx
|
||||
import React from "https://unpkg.com/react@15.6.1?module"
|
||||
import router from "https://unpkg.com/@angular/router@4.3.5?module"
|
||||
import map from "https://unpkg.com/lodash.map@4.6.0?module"
|
||||
import fs from "https://unpkg.com/pn@1.0.0/fs?module"
|
||||
import cupcakes from "./cupcakes?module"
|
||||
import shoelaces from "/shoelaces?module"
|
||||
import something from "//something.com/whatevs"
|
||||
import something from "http://something.com/whatevs"
|
||||
let ReactDOM = require("react-dom")
|
||||
export React from "https://unpkg.com/react@15.6.1?module"
|
||||
export { Component } from "https://unpkg.com/react@15.6.1?module"
|
||||
export * from "https://unpkg.com/react@15.6.1?module"
|
||||
export var message = "hello"
|
||||
```
|
|
@ -1,76 +0,0 @@
|
|||
const babel = require("babel-core")
|
||||
const unpkgRewrite = require("../index")
|
||||
|
||||
const testCases = [
|
||||
{
|
||||
before: "import React from 'react';",
|
||||
after: "import React from 'https://unpkg.com/react@15.6.1?module';"
|
||||
},
|
||||
{
|
||||
before: "import router from '@angular/router';",
|
||||
after: "import router from 'https://unpkg.com/@angular/router@4.3.5?module';"
|
||||
},
|
||||
{
|
||||
before: "import map from 'lodash.map';",
|
||||
after: "import map from 'https://unpkg.com/lodash.map@4.6.0?module';"
|
||||
},
|
||||
{
|
||||
before: "import fs from 'pn/fs';",
|
||||
after: "import fs from 'https://unpkg.com/pn@1.0.0/fs?module';"
|
||||
},
|
||||
{
|
||||
before: "import cupcakes from './cupcakes';",
|
||||
after: "import cupcakes from './cupcakes?module';"
|
||||
},
|
||||
{
|
||||
before: "import shoelaces from '/shoelaces';",
|
||||
after: "import shoelaces from '/shoelaces?module';"
|
||||
},
|
||||
{
|
||||
before: "import something from '//something.com/whatevs';",
|
||||
after: "import something from '//something.com/whatevs';"
|
||||
},
|
||||
{
|
||||
before: "import something from 'http://something.com/whatevs';",
|
||||
after: "import something from 'http://something.com/whatevs';"
|
||||
},
|
||||
{
|
||||
before: "let ReactDOM = require('react-dom');",
|
||||
after: "let ReactDOM = require('react-dom');"
|
||||
},
|
||||
{
|
||||
before: "export React from 'react';",
|
||||
after: "export React from 'https://unpkg.com/react@15.6.1?module';"
|
||||
},
|
||||
{
|
||||
before: "export { Component } from 'react';",
|
||||
after: "export { Component } from 'https://unpkg.com/react@15.6.1?module';"
|
||||
},
|
||||
{
|
||||
before: "export * from 'react';",
|
||||
after: "export * from 'https://unpkg.com/react@15.6.1?module';"
|
||||
},
|
||||
{
|
||||
before: "export var message = 'hello';",
|
||||
after: "export var message = 'hello';"
|
||||
}
|
||||
]
|
||||
|
||||
const dependencies = {
|
||||
react: "15.6.1",
|
||||
"@angular/router": "4.3.5",
|
||||
"lodash.map": "4.6.0",
|
||||
pn: "1.0.0"
|
||||
}
|
||||
|
||||
testCases.forEach(testCase => {
|
||||
describe(`rewriting "${testCase.before}"`, () => {
|
||||
it(`becomes "${testCase.after}"`, () => {
|
||||
const result = babel.transform(testCase.before, {
|
||||
plugins: [unpkgRewrite(dependencies)]
|
||||
})
|
||||
|
||||
expect(result.code).toEqual(testCase.after)
|
||||
})
|
||||
})
|
||||
})
|
|
@ -1,36 +0,0 @@
|
|||
const unpkg = require("unpkg")
|
||||
const warning = require("warning")
|
||||
|
||||
function unpkgRewrite(dependencies = {}) {
|
||||
return {
|
||||
inherits: require("babel-plugin-syntax-export-extensions"),
|
||||
|
||||
visitor: {
|
||||
"ImportDeclaration|ExportNamedDeclaration|ExportAllDeclaration"(path) {
|
||||
if (!path.node.source) return // probably a variable declaration
|
||||
|
||||
const id = path.node.source.value
|
||||
|
||||
if (unpkg.isRemoteModuleIdentifier(id)) {
|
||||
return // leave it alone
|
||||
} else if (unpkg.isLocalModuleIdentifier(id)) {
|
||||
path.node.source.value = `${id}?module`
|
||||
} else if (unpkg.isBareModuleIdentifier(id)) {
|
||||
const { packageName, file } = unpkg.parseBareModuleIdentifier(id)
|
||||
|
||||
warning(
|
||||
dependencies[packageName],
|
||||
'Missing version info for package "%s" in dependencies; falling back to "latest"',
|
||||
packageName
|
||||
)
|
||||
|
||||
const version = dependencies[packageName] || "latest"
|
||||
|
||||
path.node.source.value = `https://unpkg.com/${packageName}@${version}${file}?module`
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = unpkgRewrite
|
|
@ -1,30 +0,0 @@
|
|||
{
|
||||
"name": "babel-plugin-unpkg-rewrite",
|
||||
"version": "3.4.0",
|
||||
"description": "Rewrite bare ES module specifiers as unpkg.com URLs with Babel",
|
||||
"repository": "unpkg/unpkg",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"modules/*.js"
|
||||
],
|
||||
"main": "modules/index.js",
|
||||
"dependencies": {
|
||||
"babel-plugin-syntax-export-extensions": "^6.13.0",
|
||||
"unpkg": "^0.2.0",
|
||||
"warning": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel": "^6.23.0",
|
||||
"babel-cli": "^6.22.2",
|
||||
"babel-core": "^6.23.1"
|
||||
},
|
||||
"keywords": [
|
||||
"babel",
|
||||
"babel-plugin",
|
||||
"resolve",
|
||||
"module",
|
||||
"modules",
|
||||
"esm",
|
||||
"unpkg"
|
||||
]
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,3 +0,0 @@
|
|||
The JavaScript API for [https://unpkg.com](unpkg).
|
||||
|
||||
** Work in progress! **
|
|
@ -1,4 +0,0 @@
|
|||
exports.isBareModuleIdentifier = require("./utils/isBareModuleIdentifier")
|
||||
exports.isLocalModuleIdentifier = require("./utils/isLocalModuleIdentifier")
|
||||
exports.isRemoteModuleIdentifier = require("./utils/isRemoteModuleIdentifier")
|
||||
exports.parseBareModuleIdentifier = require("./utils/parseBareModuleIdentifier")
|
|
@ -1,19 +0,0 @@
|
|||
const isBareModuleIdentifier = require("../isBareModuleIdentifier")
|
||||
|
||||
describe("isBareModuleIdentifier", () => {
|
||||
it("returns false for local module identifiers", () => {
|
||||
expect(isBareModuleIdentifier("/absolute-path")).toBe(false)
|
||||
expect(isBareModuleIdentifier("./relative-path")).toBe(false)
|
||||
})
|
||||
|
||||
it("returns false for remote module identifiers", () => {
|
||||
expect(isBareModuleIdentifier("https://www.example.com/script.js")).toBe(false)
|
||||
expect(isBareModuleIdentifier("//www.example.com/script.js")).toBe(false)
|
||||
})
|
||||
|
||||
it("returns true for bare module identifiers", () => {
|
||||
expect(isBareModuleIdentifier("react")).toBe(true)
|
||||
expect(isBareModuleIdentifier("react-dom")).toBe(true)
|
||||
expect(isBareModuleIdentifier("react-dom/server")).toBe(true)
|
||||
})
|
||||
})
|
|
@ -1,19 +0,0 @@
|
|||
const isLocalModuleIdentifier = require("../isLocalModuleIdentifier")
|
||||
|
||||
describe("isLocalModuleIdentifier", () => {
|
||||
it("returns true for local module identifiers", () => {
|
||||
expect(isLocalModuleIdentifier("/absolute-path")).toBe(true)
|
||||
expect(isLocalModuleIdentifier("./relative-path")).toBe(true)
|
||||
})
|
||||
|
||||
it("returns false for remote module identifiers", () => {
|
||||
expect(isLocalModuleIdentifier("https://www.example.com/script.js")).toBe(false)
|
||||
expect(isLocalModuleIdentifier("//www.example.com/script.js")).toBe(false)
|
||||
})
|
||||
|
||||
it("returns false for bare module identifiers", () => {
|
||||
expect(isLocalModuleIdentifier("react")).toBe(false)
|
||||
expect(isLocalModuleIdentifier("react-dom")).toBe(false)
|
||||
expect(isLocalModuleIdentifier("react-dom/server")).toBe(false)
|
||||
})
|
||||
})
|
|
@ -1,19 +0,0 @@
|
|||
const isRemoteModuleIdentifier = require("../isRemoteModuleIdentifier")
|
||||
|
||||
describe("isRemoteModuleIdentifier", () => {
|
||||
it("returns false for local module identifiers", () => {
|
||||
expect(isRemoteModuleIdentifier("/absolute-path")).toBe(false)
|
||||
expect(isRemoteModuleIdentifier("./relative-path")).toBe(false)
|
||||
})
|
||||
|
||||
it("returns true for remote module identifiers", () => {
|
||||
expect(isRemoteModuleIdentifier("https://www.example.com/script.js")).toBe(true)
|
||||
expect(isRemoteModuleIdentifier("//www.example.com/script.js")).toBe(true)
|
||||
})
|
||||
|
||||
it("returns false for bare module identifiers", () => {
|
||||
expect(isRemoteModuleIdentifier("react")).toBe(false)
|
||||
expect(isRemoteModuleIdentifier("react-dom")).toBe(false)
|
||||
expect(isRemoteModuleIdentifier("react-dom/server")).toBe(false)
|
||||
})
|
||||
})
|
|
@ -1,38 +0,0 @@
|
|||
const parseBareModuleIdentifier = require("../parseBareModuleIdentifier")
|
||||
|
||||
describe("parseBareModuleIdentifier", () => {
|
||||
it("parses simple identifiers", () => {
|
||||
expect(parseBareModuleIdentifier("react")).toEqual({
|
||||
packageName: "react",
|
||||
file: ""
|
||||
})
|
||||
})
|
||||
|
||||
it("parses hyphenated identifiers", () => {
|
||||
expect(parseBareModuleIdentifier("react-dom")).toEqual({
|
||||
packageName: "react-dom",
|
||||
file: ""
|
||||
})
|
||||
})
|
||||
|
||||
it("parses hyphenated identifiers with a filename", () => {
|
||||
expect(parseBareModuleIdentifier("react-dom/server")).toEqual({
|
||||
packageName: "react-dom",
|
||||
file: "/server"
|
||||
})
|
||||
})
|
||||
|
||||
it("parses scoped identifiers", () => {
|
||||
expect(parseBareModuleIdentifier("@babel/core")).toEqual({
|
||||
packageName: "@babel/core",
|
||||
file: ""
|
||||
})
|
||||
})
|
||||
|
||||
it("parses scoped identifiers with a filename", () => {
|
||||
expect(parseBareModuleIdentifier("@babel/core/package.json")).toEqual({
|
||||
packageName: "@babel/core",
|
||||
file: "/package.json"
|
||||
})
|
||||
})
|
||||
})
|
|
@ -1,8 +0,0 @@
|
|||
const isLocalModuleIdentifier = require("./isLocalModuleIdentifier")
|
||||
const isRemoteModuleIdentifier = require("./isRemoteModuleIdentifier")
|
||||
|
||||
function isBareModuleIdentifier(id) {
|
||||
return !(isLocalModuleIdentifier(id) || isRemoteModuleIdentifier(id))
|
||||
}
|
||||
|
||||
module.exports = isBareModuleIdentifier
|
|
@ -1,7 +0,0 @@
|
|||
const isRemoteModuleIdentifier = require("./isRemoteModuleIdentifier")
|
||||
|
||||
function isLocalModuleIdentifier(id) {
|
||||
return [".", "/"].includes(id.charAt(0)) && !isRemoteModuleIdentifier(id)
|
||||
}
|
||||
|
||||
module.exports = isLocalModuleIdentifier
|
|
@ -1,10 +0,0 @@
|
|||
const URL = require("whatwg-url")
|
||||
|
||||
function isRemoteModuleIdentifier(id) {
|
||||
// Fully-qualified URL or URL w/out protocol
|
||||
return (
|
||||
URL.parseURL(id) !== null || (id.substr(0, 2) === "//" && URL.parseURL(`http:${id}`) !== null)
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = isRemoteModuleIdentifier
|
|
@ -1,12 +0,0 @@
|
|||
const bareModuleIdentifierFormat = /^((?:@[^\/]+\/)?[^\/]+)(\/.*)?$/
|
||||
|
||||
function parseBareModuleIdentifier(id) {
|
||||
const match = bareModuleIdentifierFormat.exec(id)
|
||||
|
||||
return {
|
||||
packageName: match[1],
|
||||
file: match[2] || ""
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = parseBareModuleIdentifier
|
|
@ -1,17 +0,0 @@
|
|||
{
|
||||
"name": "unpkg",
|
||||
"version": "0.2.0",
|
||||
"description": "The JavaScript API for unpkg",
|
||||
"repository": "unpkg/unpkg",
|
||||
"files": [
|
||||
"modules/*.js",
|
||||
"modules/utils/*.js"
|
||||
],
|
||||
"main": "modules/index.js",
|
||||
"dependencies": {
|
||||
"whatwg-url": "^6.3.0"
|
||||
},
|
||||
"keywords": [
|
||||
"unpkg"
|
||||
]
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
lodash.sortby@^4.7.0:
|
||||
version "4.7.0"
|
||||
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
|
||||
|
||||
punycode@^2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.0.tgz#5f863edc89b96db09074bad7947bf09056ca4e7d"
|
||||
|
||||
tr46@^1.0.0:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/tr46/-/tr46-1.0.1.tgz#a8b13fd6bfd2489519674ccde55ba3693b706d09"
|
||||
dependencies:
|
||||
punycode "^2.1.0"
|
||||
|
||||
webidl-conversions@^4.0.1:
|
||||
version "4.0.2"
|
||||
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"
|
||||
|
||||
whatwg-url@^6.3.0:
|
||||
version "6.3.0"
|
||||
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-6.3.0.tgz#597ee5488371abe7922c843397ddec1ae94c048d"
|
||||
dependencies:
|
||||
lodash.sortby "^4.7.0"
|
||||
tr46 "^1.0.0"
|
||||
webidl-conversions "^4.0.1"
|
Loading…
Reference in New Issue