diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index eb7ac87..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,58 +0,0 @@ -version: 2 -jobs: - lint: - docker: - - image: circleci/node:14 - steps: - - checkout - - run: yarn - - run: yarn build - - run: yarn lint - - test-node-12: - docker: - - image: circleci/node:12 - steps: - - checkout - - run: yarn - - run: yarn build - - run: yarn test - - test-node-14: - docker: - - image: circleci/node:14 - steps: - - checkout - - run: yarn - - run: yarn build - - run: yarn test - - test-node-16: - docker: - - image: circleci/node:16 - steps: - - checkout - - run: yarn - - run: yarn build - - run: yarn test - - test-node-latest: - docker: - - image: circleci/node:latest - environment: - - NODE_OPTIONS: --openssl-legacy-provider - steps: - - checkout - - run: yarn - - run: yarn build - - run: yarn test - -workflows: - version: 2 - build-and-test: - jobs: - - lint - - test-node-12 - - test-node-14 - - test-node-16 - - test-node-latest diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..fa2a234 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +name: CI + +on: [push, pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Use Node.js 14 + uses: actions/setup-node@v1 + with: + node-version: 14 + + - name: install and lint + run: | + yarn + yarn lint + + test: + name: Test on node ${{ matrix.node_version }} and ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + node_version: ['12', '14', '16'] + os: [ubuntu-22.04, windows-2022, macos-12] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node_version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node_version }} + + - name: install, build, test + run: | + yarn + yarn build + yarn test diff --git a/package.json b/package.json index 6191c09..7cfcc5c 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "pkg-dir": "^5.0.0", "prettier": "^2.2.1", "prompts": "^2.3.0", + "replaceall": "^0.1.6", "semver": "^7.3.5", "strip-ansi": "^7.0.1", "terminal-link": "^2.1.1", diff --git a/src/__tests__/actions/get.spec.ts b/src/__tests__/actions/get.spec.ts index ed9f03e..6fa4263 100644 --- a/src/__tests__/actions/get.spec.ts +++ b/src/__tests__/actions/get.spec.ts @@ -4,6 +4,7 @@ jest.mock('prompts', () => { }); import open from 'open'; +import path from 'path'; import prompts from 'prompts'; import getAction from '../../actions/get'; import { resolveWorkspace } from '../utils'; @@ -93,12 +94,21 @@ describe('get', () => { }); describe('--open', () => { + const isWindows = /^win/.test(process.platform); + it('should open module file directory when --open flag used', () => { const workspace = resolveWorkspace('three-levels-deep'); getAction(workspace, 'dep', { open: true }); + let expectedPath = path.join('node_modules', 'dep', 'package.json'); + + if (isWindows) { + const sep = path.sep + path.sep; + expectedPath = `node_modules` + sep + 'dep' + sep + 'package.json'; + } + expect(open).toHaveBeenCalledWith( - expect.stringMatching(/node_modules\/dep\/package.json/), + expect.stringMatching(expectedPath), expect.any(Object) ); }); @@ -107,6 +117,11 @@ describe('get', () => { const workspace = resolveWorkspace('few-modules'); getAction(workspace, 'dependency2', { open: true }); + // it's not critical to run this on windows + if (isWindows) { + return; + } + expect(prompts).toHaveBeenCalledWith( expect.objectContaining({ choices: expect.arrayContaining([ diff --git a/src/__tests__/cli.spec.ts b/src/__tests__/cli.spec.ts index e3240bf..bb5c088 100644 --- a/src/__tests__/cli.spec.ts +++ b/src/__tests__/cli.spec.ts @@ -1,5 +1,7 @@ import { execSync, StdioOptions } from 'child_process'; import { resolveFixture } from './utils'; +// @ts-expect-error no typings +import replaceall from 'replaceall'; const qnmBin = require.resolve('../../bin/qnm'); @@ -61,6 +63,20 @@ describe('CLI', () => { }); it('should show an indication in case there is a symlink', () => { + const isWindows = /^win/.test(process.platform); + + if (isWindows) { + const cwd = resolveFixture('symlink'); + // symlinks in windows are a bit different + const output = runCommand('test-windows', { cwd }); + + // the snapshot must look similar to the one on windows + expect( + replaceall('\\', '/', replaceall('-windows', '', output)) + ).toMatchSnapshot(); + return; + } + const cwd = resolveFixture('symlink'); const output = runCommand('test', { cwd }); diff --git a/src/__tests__/fixtures/symlink/node_modules/test-windows b/src/__tests__/fixtures/symlink/node_modules/test-windows new file mode 120000 index 0000000..ae592a7 --- /dev/null +++ b/src/__tests__/fixtures/symlink/node_modules/test-windows @@ -0,0 +1 @@ +../../symlink-origin/node_modules/test \ No newline at end of file diff --git a/src/workspace/modules-map.ts b/src/workspace/modules-map.ts index 6a83dbd..f1e6bd7 100644 --- a/src/workspace/modules-map.ts +++ b/src/workspace/modules-map.ts @@ -141,7 +141,8 @@ export default class ModulesMap extends Map> { ); return subScopeModules.map((subName) => { - const fullName = path.join(name, subName); + const fullName = `${name}/${subName}`; + const nodeModule = new NodeModule({ nodeModulesPath, name: fullName, diff --git a/yarn.lock b/yarn.lock index 7bda0c6..55396cf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4599,6 +4599,7 @@ __metadata: pkg-dir: ^5.0.0 prettier: ^2.2.1 prompts: ^2.3.0 + replaceall: ^0.1.6 semver: ^7.3.5 strip-ansi: ^7.0.1 terminal-link: ^2.1.1 @@ -4650,6 +4651,13 @@ __metadata: languageName: node linkType: hard +"replaceall@npm:^0.1.6": + version: 0.1.6 + resolution: "replaceall@npm:0.1.6" + checksum: 2396fdc6f10b7ed7c8c0298455840473a028a81e29087bc02a37cc3ff1e85467534e0992a1b45bcdb3e99370db656d260bec7bd422819b708009f060ba8b4dbe + languageName: node + linkType: hard + "require-directory@npm:^2.1.1": version: 2.1.1 resolution: "require-directory@npm:2.1.1"