Skip to content

Commit

Permalink
deps: remove mkdirp
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Feb 6, 2023
1 parent a999f24 commit a2a475f
Show file tree
Hide file tree
Showing 25 changed files with 333 additions and 364 deletions.
3 changes: 0 additions & 3 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ graph LR;
libnpmexec-->just-extend;
libnpmexec-->just-safe-set;
libnpmexec-->minify-registry-metadata;
libnpmexec-->mkdirp;
libnpmexec-->npm-package-arg;
libnpmexec-->npmcli-arborist["@npmcli/arborist"];
libnpmexec-->npmcli-eslint-config["@npmcli/eslint-config"];
Expand Down Expand Up @@ -510,7 +509,6 @@ graph LR;
npm-->minimatch;
npm-->minipass-pipeline;
npm-->minipass;
npm-->mkdirp;
npm-->ms;
npm-->nock;
npm-->node-gyp;
Expand Down Expand Up @@ -637,7 +635,6 @@ graph LR;
npmcli-docs-->ignore-walk;
npmcli-docs-->isaacs-string-locale-compare["@isaacs/string-locale-compare"];
npmcli-docs-->jsdom;
npmcli-docs-->mkdirp;
npmcli-docs-->npmcli-eslint-config["@npmcli/eslint-config"];
npmcli-docs-->npmcli-template-oss["@npmcli/template-oss"];
npmcli-docs-->rehype-stringify;
Expand Down
1 change: 0 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"front-matter": "^4.0.2",
"ignore-walk": "^6.0.0",
"jsdom": "^21.1.0",
"mkdirp": "^1.0.4",
"rehype-stringify": "^9.0.3",
"remark-gfm": "^3.0.1",
"remark-man": "^8.0.1",
Expand Down
4 changes: 0 additions & 4 deletions package-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"minimatch",
"minipass",
"minipass-pipeline",
"mkdirp",
"ms",
"node-gyp",
"nopt",
Expand Down Expand Up @@ -122,7 +121,6 @@
"minimatch": "^5.1.1",
"minipass": "^4.0.2",
"minipass-pipeline": "^1.2.4",
"mkdirp": "^1.0.4",
"ms": "^2.1.2",
"node-gyp": "^9.3.1",
"nopt": "^7.0.0",
Expand Down Expand Up @@ -188,7 +186,6 @@
"front-matter": "^4.0.2",
"ignore-walk": "^6.0.0",
"jsdom": "^21.1.0",
"mkdirp": "^1.0.4",
"rehype-stringify": "^9.0.3",
"remark-gfm": "^3.0.1",
"remark-man": "^8.0.1",
Expand Down Expand Up @@ -14590,7 +14587,6 @@
"just-extend": "^6.1.1",
"just-safe-set": "^4.2.1",
"minify-registry-metadata": "^3.0.0",
"mkdirp": "^1.0.4",
"tap": "^16.3.2"
},
"engines": {
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
"minimatch": "^5.1.1",
"minipass": "^4.0.2",
"minipass-pipeline": "^1.2.4",
"mkdirp": "^1.0.4",
"ms": "^2.1.2",
"node-gyp": "^9.3.1",
"nopt": "^7.0.0",
Expand Down Expand Up @@ -159,7 +158,6 @@
"minimatch",
"minipass",
"minipass-pipeline",
"mkdirp",
"ms",
"node-gyp",
"nopt",
Expand Down
3 changes: 1 addition & 2 deletions workspaces/arborist/.eslintrc.local.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"ignorePatterns": [
"test/fixtures/",
"!test/fixtures/*.js"
"test/fixtures/*/"
],
"rules": {
"max-len": "off",
Expand Down
4 changes: 0 additions & 4 deletions workspaces/arborist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,13 @@
},
"scripts": {
"test": "tap",
"test-only": "tap --only",
"posttest": "node ../.. run lint",
"snap": "tap",
"postsnap": "npm run lintfix",
"test-proxy": "ARBORIST_TEST_PROXY=1 tap --snapshot",
"eslint": "eslint",
"lint": "eslint \"**/*.js\"",
"lintfix": "node ../.. run lint -- --fix",
"benchmark": "node scripts/benchmark.js",
"benchclean": "rm -rf scripts/benchmark/*/",
"npmclilint": "npmcli-lint",
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force"
},
Expand Down
2 changes: 1 addition & 1 deletion workspaces/arborist/scripts/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const currentSha = String(execSync(shaCmd)).trim() + (dirty ? '-dirty' : '')
const { green, red } = require('chalk')
const lastBenchmark = resolve(__dirname, 'benchmark/saved/last-benchmark.json')
const { linkSync, writeFileSync, readdirSync } = require('fs')
const registryServer = require('../test/fixtures/registry-mocks/server.js')
const registryServer = require('../test/fixtures/server.js')

const options = {
previous: null,
Expand Down
31 changes: 8 additions & 23 deletions workspaces/arborist/test/arborist/audit.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,27 @@
const t = require('tap')
const Arborist = require('../../lib/arborist/index.js')

const { resolve } = require('path')
const Arborist = require('../../lib/arborist/index.js')
const { normalizePath, printTree } = require('../fixtures/utils.js')
const { auditResponse, advisoryBulkResponse, ...mockRegistry } = require('../fixtures/server.js')

const fixtures = resolve(__dirname, '../fixtures')

const fixture = (t, p) => require(fixtures + '/reify-cases/' + p)(t)

const {
start,
stop,
registry,
auditResponse,
advisoryBulkResponse,
} = require('../fixtures/registry-mocks/server.js')
const cache = t.testdir()

t.before(start)
t.teardown(stop)

const {
normalizePath,
printTree,
} = require('../fixtures/utils.js')
t.before(mockRegistry.start)
t.teardown(mockRegistry.stop)

const cache = t.testdir()
const newArb = (path, options = {}) =>
new Arborist({ path, cache, registry, ...options })
new Arborist({ path, cache, registry: mockRegistry.registry, ...options })

const cwd = normalizePath(process.cwd())
t.cleanSnapshot = s => s.split(cwd).join('{CWD}')
.split(registry).join('https://registry.npmjs.org/')
.split(mockRegistry.registry).join('https://registry.npmjs.org/')

t.test('audit finds the bad deps', async t => {
const path = resolve(fixtures, 'deprecated-dep')
t.teardown(auditResponse(resolve(fixtures, 'audit-nyc-mkdirp/audit.json')))

const arb = newArb(path)

const report = await arb.audit()
t.equal(report.topVulns.size, 0)
t.equal(report.size, 2)
Expand Down
2 changes: 1 addition & 1 deletion workspaces/arborist/test/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Arborist = require('../..')
const fixtures = resolve(__dirname, '../fixtures')
// load the symbolic links that we depend on
require(fixtures)
const { start, stop, registry, auditResponse } = require('../fixtures/registry-mocks/server.js')
const { start, stop, registry, auditResponse } = require('../fixtures/server.js')
const npa = require('npm-package-arg')
const fs = require('fs')
const nock = require('nock')
Expand Down
2 changes: 1 addition & 1 deletion workspaces/arborist/test/arborist/deduper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const t = require('tap')
const Arborist = require('../../lib/arborist/index.js')

const { start, stop, registry } = require('../fixtures/registry-mocks/server.js')
const { start, stop, registry } = require('../fixtures/server.js')
t.before(start)
t.teardown(stop)

Expand Down
2 changes: 1 addition & 1 deletion workspaces/arborist/test/arborist/pruner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { resolve } = require('path')
const t = require('tap')
const Arborist = require('../../lib/arborist/index.js')

const { start, stop, registry } = require('../fixtures/registry-mocks/server.js')
const { start, stop, registry } = require('../fixtures/server.js')

t.before(start)
t.teardown(stop)
Expand Down
2 changes: 1 addition & 1 deletion workspaces/arborist/test/arborist/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const {
stop,
registry,
advisoryBulkResponse,
} = require('../fixtures/registry-mocks/server.js')
} = require('../fixtures/server.js')

t.before(start)
t.teardown(stop)
Expand Down
2 changes: 1 addition & 1 deletion workspaces/arborist/test/audit-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const {
auditResponse,
failAudit,
advisoryBulkResponse,
} = require('./fixtures/registry-mocks/server.js')
} = require('./fixtures/server.js')
t.before(start)
t.teardown(stop)

Expand Down
11 changes: 5 additions & 6 deletions workspaces/arborist/test/fixtures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The reify test case fixtures are stored in `test/fixtures/reify-cases/`.
To generate a new test case:

```
node test/fixtures/reify-cases/create.js <folder>
node test/fixtures/create-reify-case.js <folder>
```

where `<folder>` is a path to the test case example you wish to store.
Expand All @@ -61,22 +61,21 @@ much garbage or extraneous files that aren't relevant to the test.

## Mock Registry

The mock registry is in `test/fixtures/registry-mocks`. The server itself
is in `test/fixtures/registry-mocks/server.js`. The contents are in
The mock registry server is in `test/fixtures/server.js` and the contents are in
`test/fixtures/registry-mocks/content/`.

You can run the server directly by running:

```
node test/fixtures/registry-mocks/server.js
node test/fixtures/server.js
```

In tests, it's loaded by requiring the server module, and then running the
exported method, passing in a `tap` test object, and using the exported
`registry` property as the registry config for all its business.

```js
const {start, stop, registry} = require('../fixtures/registry-mocks/server.js')
const {start, stop, registry} = require('../fixtures/server.js')
t.before(start)
t.teardown(stop)

Expand All @@ -103,7 +102,7 @@ The server will fetch whatever it doesn't have from the registry, and save
it in the appropriate place under `test/fixtures/registry-mocks/content/`.

There is also a script at
`test/fixtures/registry-mocks/fetch-lock-contents.js` which will fetch and
`test/fixtures/fetch-lock-contents.js` which will fetch and
store the packuments and tarballs referenced in a `package-lock.json` file.

And of course, you could just delete the entire `content` folder and run
Expand Down
11 changes: 7 additions & 4 deletions workspaces/arborist/test/fixtures/cleanup.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const { resolve } = require('path')
const { readdirSync, lstatSync } = require('fs')

process.env.ARBORIST_FIXTURE_CLEANUP = '1'
require('./index.js')

// now make sure it actually did clean up everything
const { readdirSync, lstatSync } = require('fs')
const readdir = (path, opt) => {
const ents = readdirSync(path, opt)
if (typeof ents[0] === 'string') {
Expand All @@ -13,15 +15,16 @@ const readdir = (path, opt) => {
return ents
}

const { resolve } = require('path')
const walk = dir => {
for (const entry of readdir(dir, { withFileTypes: true })) {
if (entry.isDirectory())
if (entry.isDirectory()) {
walk(resolve(dir, entry.name))
else if (entry.isSymbolicLink())
} else if (entry.isSymbolicLink()) {
throw Object.assign(new Error('symlink left in fixtures dir'), {
path: resolve(dir, entry.name),
})
}
}
}

walk(__dirname)
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ const {
writeFileSync,
} = require('fs')

const {resolve, relative, basename} = require('path')
const { resolve, relative, basename } = require('path')

if (!process.argv[2]) {
console.error('pass in a folder as an argument')
process.exit(1)
}

const fixture = resolve(process.argv[2])
const rel = relative(resolve(__dirname, '../../..'), fixture)
const outFile = resolve(__dirname, basename(fixture)) + '.js'
const rel = relative(resolve(__dirname, '../..'), fixture)
const outFile = resolve(__dirname, 'reify-cases', basename(fixture)) + '.js'

// we build up an object and then JSON.stringify it, and string replace
// the tokens with `t.fixture('symlink', ${symlinks.get(token)})`
Expand All @@ -34,18 +34,20 @@ const hiddenLocks = []
const readFixture = dir => {
const res = {}
for (const ent of readdirSync(dir, { withFileTypes: true })) {
if (/^\..*\.swp/.test(ent.name))
if (/^\..*\.swp/.test(ent.name)) {
continue
}

const p = resolve(dir, ent.name)
if (ent.isDirectory())
if (ent.isDirectory()) {
res[ent.name] = readFixture(p)
else if (ent.isFile()) {
} else if (ent.isFile()) {
const content = readFileSync(p, 'utf8')
const buf = readFileSync(p)
// make sure hidden lockfiles are newer than the contents they cover
if (ent.name === '.package-lock.json')
if (ent.name === '.package-lock.json') {
hiddenLocks.push(relative(fixture, p))
}

// if it's JSON, then store it in a way that's easier to look at
try {
Expand All @@ -60,8 +62,9 @@ const readFixture = dir => {
const t = token(p)
longFiles.set(t, content)
res[ent.name] = t
} else
} else {
res[ent.name] = content
}
} else {
// save as a buffer if it's binary data
const t = token(p)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
// fetch all the deps and tarballs in a v2 lockfile
const pacote = require('pacote')
const Arborist = require('../../index.js')
const url = require('url')
const mkdirp = require('mkdirp')
const {dirname, resolve} = require('path')
const {writeFileSync} = require('fs')
const dir = resolve(__dirname, 'content')
const nm = /^.*node_modules\/(@[^\/]+\/[^\/]+|[^@\/][^\/]*)$/
const { dirname, resolve } = require('path')
const fs = require('fs/promises')
const Arborist = require('./index.js')

const dir = resolve(__dirname, 'registry-mocks', 'content')
const nm = /^.*node_modules\/(@[^/]+\/[^/]+|[^@/][^/]*)$/

const main = async lock => {
for (const [loc, meta] of Object.entries(lock.packages)) {
if (!loc || meta.link || !nm.test(loc))
if (!loc || meta.link || !nm.test(loc)) {
continue
}

const name = meta.name || loc.replace(nm, '$1')

console.error('FETCHING', name)

const paku = await pacote.packument(name, { fullMetadata: true })
const saveTo = resolve(dir, name.replace(/^@/, '') + '.json')
mkdirp.sync(dirname(saveTo))
writeFileSync(saveTo, JSON.stringify(paku, 0, 2))
await fs.mkdir(dirname(saveTo), { recursive: true })
await fs.writeFile(saveTo, JSON.stringify(paku, 0, 2))

const corgi = await pacote.packument(name, {})
const corgiSaveTo = resolve(dir, name.replace(/^@/, '') + '.min.json')
writeFileSync(corgiSaveTo, JSON.stringify(corgi, 0, 2))
await fs.writeFile(corgiSaveTo, JSON.stringify(corgi, 0, 2))

// bundled deps sometimes don't have a resolved value
if (!meta.resolved)
if (!meta.resolved) {
continue
}
// eslint-disable-next-line node/no-deprecated-api
const path = url.parse(meta.resolved).pathname.replace(/^\/@?/, '')
const tgzFile = resolve(dir, path)
await pacote.tarball.file(meta.resolved, tgzFile, { Arborist })
Expand Down
Loading

0 comments on commit a2a475f

Please sign in to comment.