Runtime-deprecate ospec, change change-log to changelog, fix a few assorted bugs (#2578)

This commit is contained in:
Isiah Meadows 2020-09-29 13:27:07 -07:00 committed by GitHub
parent 1630b06106
commit 9f0dc2ab46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
76 changed files with 484 additions and 410 deletions

View file

@ -143,7 +143,7 @@ class Generator {
let anchor = text.toLowerCase()
.replace(/<(\/?)code>/g, "")
.replace(/<a.*?>.+?<\/a>/g, "")
.replace(/\.|\[|\]|&quot;|\/|\(|\)/g, "")
.replace(/[.`[\]\/()]|&quot;/g, "")
.replace(/\s/g, "-");
const anchorId = anchorIds.get(anchor)

View file

@ -278,8 +278,8 @@ async function lintAll({useCache}) {
await new Promise((resolve, reject) => {
const glob = new Glob(path.resolve(__dirname, "../**/*.md"), {
ignore: [
"**/change-log.md",
"**/migration-v02x.md",
"**/changelog.md",
"**/migration-*.md",
"**/node_modules/**",
],
nodir: true,
@ -304,10 +304,10 @@ if (require.main === module) {
exec: lintAll,
watch() {
require("chokidar")
.watch(path.resolve(__dirname, "../**/*.md"), {
ignored: [
"**/change-log.md",
"**/migration-v02x.md",
.watch(path.resolve(__dirname, "../docs/**/*.md"), {
ignore: [
"**/changelog.md",
"**/migration-*.md",
"**/node_modules/**",
],
})

View file

@ -123,7 +123,7 @@ async function release({increment, preid, publish}) {
console.error(`
Copy the parts listed in "Upcoming" to a new section "### v${version}" in
docs/change-log.md and clear that section out. Also, add today's date under the
docs/changelog.md and clear that section out. Also, add today's date under the
new section's heading to match the others and don't forget to update the table
of contents accordingly.
`)
@ -138,7 +138,7 @@ of contents accordingly.
// Verify the changelog was updated, and give a chance to retry if it's
// prematurely continued.
const changes = getChanges()
const isChangelog = /^[ M][ M] docs\/change-log\.md$/
const isChangelog = /^[ M][ M] docs\/changelog\.md$/
const errors = []
console.log("changes", changes)

View file

@ -2,22 +2,24 @@
const fs = require("fs")
const util = require("util")
const path = require("path")
const access = util.promisify(fs.access)
const writeFile = util.promisify(fs.writeFile)
const unlink = util.promisify(fs.unlink)
const o = require("../../ospec/ospec")
const o = require("ospec")
const bundle = require("../_bundler-impl")
o.spec("bundler", async () => {
let filesCreated
const ns = "./"
const root = path.resolve(__dirname, "../..")
const p = (file) => path.join(root, file)
async function write(filepath, data) {
try {
await access(ns + filepath)
await access(p(filepath))
} catch (e) {
return writeFile(ns + filepath, data, "utf8")
return writeFile(p(filepath), data, "utf8")
}
throw new Error(`Don't call \`write('${filepath}')\`. Cannot overwrite file.`)
}
@ -28,7 +30,7 @@ o.spec("bundler", async () => {
}
o.afterEach(() => Promise.all(
filesCreated.map((filepath) => unlink(ns + filepath))
filesCreated.map((filepath) => unlink(p(filepath)))
))
o("relative imports works", async () => {
@ -37,7 +39,7 @@ o.spec("bundler", async () => {
"b.js": "module.exports = 1",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nvar b = 1\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nvar b = 1\n}());")
})
o("relative imports works with semicolons", async () => {
await setup({
@ -45,7 +47,7 @@ o.spec("bundler", async () => {
"b.js": "module.exports = 1;",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nvar b = 1;\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nvar b = 1;\n}());")
})
o("relative imports works with let", async () => {
await setup({
@ -53,7 +55,7 @@ o.spec("bundler", async () => {
"b.js": "module.exports = 1",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nlet b = 1\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nlet b = 1\n}());")
})
o("relative imports works with const", async () => {
await setup({
@ -61,7 +63,7 @@ o.spec("bundler", async () => {
"b.js": "module.exports = 1",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nconst b = 1\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nconst b = 1\n}());")
})
o("relative imports works with assignment", async () => {
await setup({
@ -69,7 +71,7 @@ o.spec("bundler", async () => {
"b.js": "module.exports = 1",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nvar a = {}\na.b = 1\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nvar a = {}\na.b = 1\n}());")
})
o("relative imports works with reassignment", async () => {
await setup({
@ -77,7 +79,7 @@ o.spec("bundler", async () => {
"b.js": "module.exports = 1",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nvar b = {}\nb = 1\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nvar b = {}\nb = 1\n}());")
})
o("relative imports removes extra use strict", async () => {
await setup({
@ -85,7 +87,7 @@ o.spec("bundler", async () => {
"b.js": '"use strict"\nmodule.exports = 1',
})
o(await bundle(ns + "a.js")).equals(';(function() {\n"use strict"\nvar b = 1\n}());')
o(await bundle(p("a.js"))).equals(';(function() {\n"use strict"\nvar b = 1\n}());')
})
o("relative imports removes extra use strict using single quotes", async () => {
await setup({
@ -93,7 +95,7 @@ o.spec("bundler", async () => {
"b.js": "'use strict'\nmodule.exports = 1",
})
o(await bundle(ns + "a.js")).equals(";(function() {\n'use strict'\nvar b = 1\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\n'use strict'\nvar b = 1\n}());")
})
o("relative imports removes extra use strict using mixed quotes", async () => {
await setup({
@ -101,7 +103,7 @@ o.spec("bundler", async () => {
"b.js": "'use strict'\nmodule.exports = 1",
})
o(await bundle(ns + "a.js")).equals(';(function() {\n"use strict"\nvar b = 1\n}());')
o(await bundle(p("a.js"))).equals(';(function() {\n"use strict"\nvar b = 1\n}());')
})
o("works w/ window", async () => {
await setup({
@ -109,7 +111,7 @@ o.spec("bundler", async () => {
"b.js": "module.exports = function() {return a}",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nwindow.a = 1\nvar b = function() {return a}\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nwindow.a = 1\nvar b = function() {return a}\n}());")
})
o("works without assignment", async () => {
await setup({
@ -117,7 +119,7 @@ o.spec("bundler", async () => {
"b.js": "1 + 1",
})
o(await bundle(ns + "a.js")).equals(";(function() {\n1 + 1\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\n1 + 1\n}());")
})
o("works if used fluently", async () => {
await setup({
@ -125,7 +127,7 @@ o.spec("bundler", async () => {
"b.js": "module.exports = []",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nvar _0 = []\nvar b = _0.toString()\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nvar _0 = []\nvar b = _0.toString()\n}());")
})
o("works if used fluently w/ multiline", async () => {
await setup({
@ -133,7 +135,7 @@ o.spec("bundler", async () => {
"b.js": "module.exports = []",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nvar _0 = []\nvar b = _0\n\t.toString()\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nvar _0 = []\nvar b = _0\n\t.toString()\n}());")
})
o("works if used w/ curry", async () => {
await setup({
@ -141,7 +143,7 @@ o.spec("bundler", async () => {
"b.js": "module.exports = function() {}",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nvar _0 = function() {}\nvar b = _0()\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nvar _0 = function() {}\nvar b = _0()\n}());")
})
o("works if used w/ curry w/ multiline", async () => {
await setup({
@ -149,7 +151,7 @@ o.spec("bundler", async () => {
"b.js": "module.exports = function() {}",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nvar _0 = function() {}\nvar b = _0\n()\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nvar _0 = function() {}\nvar b = _0\n()\n}());")
})
o("works if used fluently in one place and not in another", async () => {
await setup({
@ -158,7 +160,7 @@ o.spec("bundler", async () => {
"c.js": 'var b = require("./b")\nmodule.exports = function() {return b}',
})
o(await bundle(ns + "a.js")).equals(";(function() {\nvar _0 = []\nvar b = _0.toString()\nvar b0 = _0\nvar c = function() {return b0}\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nvar _0 = []\nvar b = _0.toString()\nvar b0 = _0\nvar c = function() {return b0}\n}());")
})
o("works if used in sequence", async () => {
await setup({
@ -167,7 +169,7 @@ o.spec("bundler", async () => {
"c.js": "var x\nmodule.exports = 2",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nvar b = 1\nvar x\nvar c = 2\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nvar b = 1\nvar x\nvar c = 2\n}());")
})
o("works if assigned to property", async () => {
await setup({
@ -176,7 +178,7 @@ o.spec("bundler", async () => {
"c.js": "var cc = 2\nmodule.exports = cc",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nvar x = {}\nvar bb = 1\nx.b = bb\nvar cc = 2\nx.c = cc\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nvar x = {}\nvar bb = 1\nx.b = bb\nvar cc = 2\nx.c = cc\n}());")
})
o("works if assigned to property using bracket notation", async () => {
await setup({
@ -185,7 +187,7 @@ o.spec("bundler", async () => {
"c.js": "var cc = 2\nmodule.exports = cc",
})
o(await bundle(ns + "a.js")).equals(';(function() {\nvar x = {}\nvar bb = 1\nx["b"] = bb\nvar cc = 2\nx["c"] = cc\n}());')
o(await bundle(p("a.js"))).equals(';(function() {\nvar x = {}\nvar bb = 1\nx["b"] = bb\nvar cc = 2\nx["c"] = cc\n}());')
})
o("works if collision", async () => {
await setup({
@ -193,7 +195,7 @@ o.spec("bundler", async () => {
"b.js": "var b = 1\nmodule.exports = 2",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nvar b0 = 1\nvar b = 2\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nvar b0 = 1\nvar b = 2\n}());")
})
o("works if multiple aliases", async () => {
await setup({
@ -202,7 +204,7 @@ o.spec("bundler", async () => {
"c.js": "var b = {}\nmodule.exports = b",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nvar b = {}\nb.x = 1\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nvar b = {}\nb.x = 1\n}());")
})
o("works if multiple collision", async () => {
await setup({
@ -212,7 +214,7 @@ o.spec("bundler", async () => {
"d.js": "var a = 3\nmodule.exports = a",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nvar a = 1\nvar b = a\nvar a0 = 2\nvar c = a0\nvar a1 = 3\nvar d = a1\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nvar a = 1\nvar b = a\nvar a0 = 2\nvar c = a0\nvar a1 = 3\nvar d = a1\n}());")
})
o("works if included multiple times", async () => {
await setup({
@ -221,7 +223,7 @@ o.spec("bundler", async () => {
"c.js": 'var a = require("./a").toString()\nvar b = require("./b")',
})
o(await bundle(ns + "c.js")).equals(";(function() {\nvar _0 = 123\nvar a = _0.toString()\nvar a0 = _0.toString()\nvar b = a0\n}());")
o(await bundle(p("c.js"))).equals(";(function() {\nvar _0 = 123\nvar a = _0.toString()\nvar a0 = _0.toString()\nvar b = a0\n}());")
})
o("works if included multiple times reverse", async () => {
await setup({
@ -230,7 +232,7 @@ o.spec("bundler", async () => {
"c.js": 'var b = require("./b")\nvar a = require("./a").toString()',
})
o(await bundle(ns + "c.js")).equals(";(function() {\nvar _0 = 123\nvar a0 = _0.toString()\nvar b = a0\nvar a = _0.toString()\n}());")
o(await bundle(p("c.js"))).equals(";(function() {\nvar _0 = 123\nvar a0 = _0.toString()\nvar b = a0\nvar a = _0.toString()\n}());")
})
o("reuses binding if possible", async () => {
await setup({
@ -240,7 +242,7 @@ o.spec("bundler", async () => {
"d.js": "module.exports = 1",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nvar d = 1\nvar b = function() {return d + 1}\nvar c = function() {return d + 2}\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nvar d = 1\nvar b = function() {return d + 1}\nvar c = function() {return d + 2}\n}());")
})
o("disambiguates conflicts if imported collides with itself", async () => {
await setup({
@ -248,7 +250,7 @@ o.spec("bundler", async () => {
"b.js": "var b = 1\nmodule.exports = function() {return b}",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nvar b0 = 1\nvar b = function() {return b0}\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nvar b0 = 1\nvar b = function() {return b0}\n}());")
})
o("disambiguates conflicts if imported collides with something else", async () => {
await setup({
@ -256,7 +258,7 @@ o.spec("bundler", async () => {
"b.js": "var a = 2\nmodule.exports = function() {return a}",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nvar a = 1\nvar a0 = 2\nvar b = function() {return a0}\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nvar a = 1\nvar a0 = 2\nvar b = function() {return a0}\n}());")
})
o("disambiguates conflicts if imported collides with function declaration", async () => {
await setup({
@ -264,7 +266,7 @@ o.spec("bundler", async () => {
"b.js": "var a = 2\nmodule.exports = function() {return a}",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nfunction a() {}\nvar a0 = 2\nvar b = function() {return a0}\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nfunction a() {}\nvar a0 = 2\nvar b = function() {return a0}\n}());")
})
o("disambiguates conflicts if imported collides with another module's private", async () => {
await setup({
@ -273,7 +275,7 @@ o.spec("bundler", async () => {
"c.js": "var a = 2\nmodule.exports = function() {return a}",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nvar a = 1\nvar b = function() {return a}\nvar a0 = 2\nvar c = function() {return a0}\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nvar a = 1\nvar b = function() {return a}\nvar a0 = 2\nvar c = function() {return a0}\n}());")
})
o("does not mess up strings", async () => {
await setup({
@ -281,7 +283,7 @@ o.spec("bundler", async () => {
"b.js": 'var b = "b b b \\" b"\nmodule.exports = function() {return b}',
})
o(await bundle(ns + "a.js")).equals(';(function() {\nvar b0 = "b b b \\\" b"\nvar b = function() {return b0}\n}());')
o(await bundle(p("a.js"))).equals(';(function() {\nvar b0 = "b b b \\\" b"\nvar b = function() {return b0}\n}());')
})
o("does not mess up properties", async () => {
await setup({
@ -289,6 +291,6 @@ o.spec("bundler", async () => {
"b.js": "var b = {b: 1}\nmodule.exports = function() {return b.b}",
})
o(await bundle(ns + "a.js")).equals(";(function() {\nvar b0 = {b: 1}\nvar b = function() {return b0.b}\n}());")
o(await bundle(p("a.js"))).equals(";(function() {\nvar b0 = {b: 1}\nvar b = function() {return b0.b}\n}());")
})
})