-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix(ci): rm workspace node_modules #7490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d08cd4b
fix(ci): rm workspace node_modules
reggi 8459bf3
chore: update setWorkspaceFlagIndependent comment
reggi 807c017
simplify setting ws
reggi 6a72f97
adds test, use set to dedupe
reggi dd27745
consolidate workspace vars
reggi 9c088d5
rm another licence"
reggi 0a81f20
rm where
reggi 142fe7a
fix spread over map
reggi d4e23d4
added tests, handle workspace flag behavor
reggi b7fc789
rm disable max-len
reggi afdb6f3
cleanup fixtures
reggi 8657864
fix smoke
reggi 7e70e01
rollback arborist-ws-cmd, keep ws bau, remove all node_modules for ci
reggi c60e4f4
comment test
reggi 4cf3f2a
add workspace back to ci, add pre command assertions
reggi 37bb0f2
undo arboist-cmd test rename
reggi e63c442
add new export to the bottom
reggi d23bd85
rm local assert call
reggi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| const os = require('os') | ||
| const fs = require('fs').promises | ||
| const fsSync = require('fs') | ||
| const path = require('path') | ||
| const tap = require('tap') | ||
| const mockLogs = require('./mock-logs.js') | ||
| const mockGlobals = require('@npmcli/mock-globals') | ||
| const tmock = require('./tmock') | ||
| const MockRegistry = require('@npmcli/mock-registry') | ||
| const defExitCode = process.exitCode | ||
|
|
||
| const changeDir = (dir) => { | ||
|
|
@@ -288,6 +290,167 @@ const setupMockNpm = async (t, { | |
| } | ||
| } | ||
|
|
||
| const loadNpmWithRegistry = async (t, opts) => { | ||
| const mock = await setupMockNpm(t, opts) | ||
| const registry = new MockRegistry({ | ||
| tap: t, | ||
| registry: mock.npm.config.get('registry'), | ||
| strict: true, | ||
| }) | ||
|
|
||
| const fileShouldExist = (filePath) => { | ||
| t.equal( | ||
| fsSync.existsSync(path.join(mock.npm.prefix, filePath)), true, `${filePath} should exist` | ||
| ) | ||
| } | ||
|
|
||
| const fileShouldNotExist = (filePath) => { | ||
| t.equal( | ||
| fsSync.existsSync(path.join(mock.npm.prefix, filePath)), false, `${filePath} should not exist` | ||
| ) | ||
| } | ||
|
|
||
| const packageVersionMatches = (filePath, version) => { | ||
| t.equal( | ||
| JSON.parse(fsSync.readFileSync(path.join(mock.npm.prefix, filePath), 'utf8')).version, version | ||
| ) | ||
| } | ||
|
|
||
| const packageInstalled = (target) => { | ||
| const spec = path.basename(target) | ||
| const dirname = path.dirname(target) | ||
| const [name, version = '1.0.0'] = spec.split('@') | ||
| assert.fileShouldNotExist(`${dirname}/${name}/${name}@${version}.txt`) | ||
wraithgar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assert.packageVersionMatches(`${dirname}/${name}/package.json`, version) | ||
| assert.fileShouldExist(`${dirname}/${name}/index.js`) | ||
| } | ||
|
|
||
| const packageMissing = (target) => { | ||
| const spec = path.basename(target) | ||
| const dirname = path.dirname(target) | ||
| const [name, version = '1.0.0'] = spec.split('@') | ||
| assert.fileShouldNotExist(`${dirname}/${name}/${name}@${version}.txt`) | ||
| assert.fileShouldNotExist(`${dirname}/${name}/package.json`) | ||
| assert.fileShouldNotExist(`${dirname}/${name}/index.js`) | ||
| } | ||
|
|
||
| const packageDirty = (target) => { | ||
| const spec = path.basename(target) | ||
| const dirname = path.dirname(target) | ||
| const [name, version = '1.0.0'] = spec.split('@') | ||
| assert.fileShouldExist(`${dirname}/${name}/${name}@${version}.txt`) | ||
| assert.packageVersionMatches(`${dirname}/${name}/package.json`, version) | ||
| assert.fileShouldNotExist(`${dirname}/${name}/index.js`) | ||
| } | ||
|
|
||
| const assert = { | ||
| fileShouldExist, | ||
| fileShouldNotExist, | ||
| packageVersionMatches, | ||
| packageInstalled, | ||
| packageMissing, | ||
| packageDirty, | ||
| } | ||
|
|
||
| return { registry, assert, ...mock } | ||
| } | ||
|
|
||
| /** breaks down a spec "[email protected]" into different parts for mocking */ | ||
| function dependencyDetails (spec, opt = {}) { | ||
| const [name, version = '1.0.0'] = spec.split('@') | ||
| const { parent, hoist = true, ws, clean = true } = opt | ||
| const modulePathPrefix = !hoist && parent ? `${parent}/` : '' | ||
| const modulePath = `${modulePathPrefix}node_modules/${name}` | ||
| const resolved = `https://registry.npmjs.org/${name}/-/${name}-${version}.tgz` | ||
| // deps | ||
| const wsEntries = Object.entries({ ...ws }) | ||
| const depsMap = wsEntries.map(([s, o]) => dependencyDetails(s, { ...o, parent: name })) | ||
| const dependencies = Object.assign({}, ...depsMap.map(d => d.packageDependency)) | ||
| const spreadDependencies = depsMap.length ? { dependencies } : {} | ||
| // package and lock objects | ||
| const packageDependency = { [name]: version } | ||
| const packageLockEntry = { [modulePath]: { version, resolved } } | ||
| const packageLockLink = { [modulePath]: { resolved: name, link: true } } | ||
| const packageLockLocal = { [name]: { version, dependencies } } | ||
| // build package.js | ||
| const packageJSON = { name, version, ...spreadDependencies } | ||
| const packageJSONString = JSON.stringify(packageJSON) | ||
| const packageJSONFile = { 'package.json': packageJSONString } | ||
| // build index.js | ||
| const indexJSString = 'module.exports = "hello world"' | ||
| const indexJSFile = { 'index.js': indexJSString } | ||
| // tarball | ||
| const packageFiles = { ...packageJSONFile, ...indexJSFile } | ||
| const nodeModules = Object.assign({}, ...depsMap.map(d => d.hoist ? {} : d.dirtyOrCleanDir)) | ||
| const nodeModulesDir = { node_modules: nodeModules } | ||
| const packageDir = { [name]: { ...packageFiles, ...nodeModulesDir } } | ||
| const tarballDir = { [`${name}@${version}`]: packageFiles } | ||
| // dirty files | ||
| const dirtyFile = { [`${name}@${version}.txt`]: 'dirty file' } | ||
| const dirtyFiles = { ...packageJSONFile, ...dirtyFile } | ||
| const dirtyDir = { [name]: dirtyFiles } | ||
| const dirtyOrCleanDir = clean ? {} : dirtyDir | ||
|
|
||
| return { | ||
| packageDependency, | ||
| hoist, | ||
| depsMap, | ||
| dirtyOrCleanDir, | ||
| tarballDir, | ||
| packageDir, | ||
| packageLockEntry, | ||
| packageLockLink, | ||
| packageLockLocal, | ||
| } | ||
| } | ||
|
|
||
| function workspaceMock (t, opts) { | ||
| const toObject = [(a, c) => ({ ...a, ...c }), {}] | ||
| const { workspaces: workspacesDef, ...rest } = { clean: true, ...opts } | ||
| const workspaces = Object.fromEntries(Object.entries(workspacesDef).map(([name, ws]) => { | ||
| return [name, Object.fromEntries(Object.entries(ws).map(([wsPackageDep, wsPackageDepOpts]) => { | ||
| return [wsPackageDep, { ...rest, ...wsPackageDepOpts }] | ||
| }))] | ||
| })) | ||
| const root = 'workspace-root' | ||
| const version = '1.0.0' | ||
| const names = Object.keys(workspaces) | ||
| const ws = Object.entries(workspaces).map(([name, _ws]) => dependencyDetails(name, { ws: _ws })) | ||
| const deps = ws.map(({ depsMap }) => depsMap).flat() | ||
| const tarballs = deps.map(w => w.tarballDir).reduce(...toObject) | ||
| const symlinks = names | ||
| .map((name) => ({ [name]: t.fixture('symlink', `../${name}`) })).reduce(...toObject) | ||
| const hoisted = deps.filter(d => d.hoist).map(w => w.dirtyOrCleanDir).reduce(...toObject) | ||
| const workspaceFolders = ws.map(w => w.packageDir).reduce(...toObject) | ||
| const packageJSON = { name: root, version, workspaces: names } | ||
| const packageLockJSON = ({ | ||
| name: root, | ||
| version, | ||
| lockfileVersion: 3, | ||
| requires: true, | ||
| packages: { | ||
| '': { name: root, version, workspaces: names }, | ||
| ...deps.filter(d => d.hoist).map(d => d.packageLockEntry).reduce(...toObject), | ||
| ...ws.map(d => d.packageLockEntry).flat().reduce(...toObject), | ||
| ...ws.map(d => d.packageLockLink).flat().reduce(...toObject), | ||
| ...ws.map(d => d.packageLockLocal).flat().reduce(...toObject), | ||
| ...deps.filter(d => !d.hoist).map(d => d.packageLockEntry).reduce(...toObject), | ||
| }, | ||
| }) | ||
| return { | ||
| tarballs, | ||
| node_modules: { | ||
| ...hoisted, | ||
| ...symlinks, | ||
| }, | ||
| 'package-lock.json': JSON.stringify(packageLockJSON), | ||
| 'package.json': JSON.stringify(packageJSON), | ||
| ...workspaceFolders, | ||
| } | ||
| } | ||
|
|
||
| module.exports = setupMockNpm | ||
| module.exports.load = setupMockNpm | ||
| module.exports.setGlobalNodeModules = setGlobalNodeModules | ||
| module.exports.loadNpmWithRegistry = loadNpmWithRegistry | ||
| module.exports.workspaceMock = workspaceMock | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.