diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f8f20f0f..0a15f421 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -30,7 +30,7 @@ jobs: - run: npm run types - - run: npm run test:ci + - run: npm test - run: npx semantic-release env: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f89c73f5..fcb4327d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: test: strategy: matrix: - os: [ubuntu-latest, macOS-latest] #, windows-latest] + os: [ubuntu-latest, macOS-latest, windows-latest] node-version: [20] runs-on: ${{ matrix.os }} @@ -30,4 +30,4 @@ jobs: - run: npm run types - - run: npm run test:ci + - run: npm test diff --git a/classes/alias.js b/classes/alias.js index 41d3acfa..1fb27b70 100644 --- a/classes/alias.js +++ b/classes/alias.js @@ -1,9 +1,9 @@ import assert from 'assert'; import abslog from 'abslog'; -import { join } from 'path'; import { schemas, validators } from '@eik/common'; import { request } from '../utils/http/index.js'; import { typeSlug } from '../utils/index.js'; +import { joinUrlPathname } from '../utils/url.js'; /** * @typedef {object} AliasOptions @@ -74,7 +74,11 @@ export default class Alias { `Requesting creation of ${this.type} alias "v${this.alias}" for ${this.name} v${this.version} on ${this.server}`, ); - const pathname = join(this.type, this.name, `v${this.alias}`); + const pathname = joinUrlPathname( + this.type, + this.name, + `v${this.alias}`, + ); try { const { message } = await request({ host: this.server, diff --git a/classes/integrity.js b/classes/integrity.js index d6ae95f6..4b162181 100644 --- a/classes/integrity.js +++ b/classes/integrity.js @@ -1,7 +1,7 @@ import abslog from 'abslog'; -import { join } from 'path'; import eik from '@eik/common'; import { typeSlug } from '../utils/index.js'; +import { joinUrlPathname } from '../utils/url.js'; const { schemas } = eik; @@ -79,7 +79,7 @@ export default class Integrity { this.log.debug('Requesting meta information from asset server'); try { const url = new URL( - join(typeSlug(this.type), this.name, this.version), + joinUrlPathname(typeSlug(this.type), this.name, this.version), this.server, ); this.log.debug(` ==> url: ${url}`); diff --git a/classes/meta.js b/classes/meta.js index 6d510215..47b0479d 100644 --- a/classes/meta.js +++ b/classes/meta.js @@ -1,6 +1,6 @@ import abslog from 'abslog'; -import { join } from 'path'; import { schemas } from '@eik/common'; +import { joinUrlPathname } from '../utils/url.js'; const types = ['pkg', 'map', 'npm']; @@ -40,7 +40,10 @@ export default class Meta { try { const typeFetches = []; for (const type of types) { - const url = new URL(join(type, this.name), this.server); + const url = new URL( + joinUrlPathname(type, this.name), + this.server, + ); url.search = `?t=${Date.now()}`; typeFetches.push(fetch(url)); } @@ -64,7 +67,7 @@ export default class Meta { for (let i = 0; i < data[type].versions.length; i++) { const { version } = data[type].versions[i]; const url = new URL( - join(type, name, version), + joinUrlPathname(type, name, version), this.server, ); diff --git a/classes/publish/map.js b/classes/publish/map.js index 485b9b7c..1225e283 100644 --- a/classes/publish/map.js +++ b/classes/publish/map.js @@ -4,6 +4,7 @@ import { join, parse, isAbsolute } from 'path'; import { existsSync } from 'fs'; import { schemas } from '@eik/common'; import { request } from '../../utils/http/index.js'; +import { joinUrlPathname } from '../../utils/url.js'; /** * @typedef {object} PublishMapOptions @@ -79,7 +80,7 @@ export default class PublishMap { await request({ method: 'PUT', host: this.server, - pathname: join('map', this.name, this.version), + pathname: joinUrlPathname('map', this.name, this.version), map: this.absoluteFile, token: this.token, }); diff --git a/classes/publish/package/tasks/check-if-already-published.js b/classes/publish/package/tasks/check-if-already-published.js index 7baf7f62..8ba9f30e 100644 --- a/classes/publish/package/tasks/check-if-already-published.js +++ b/classes/publish/package/tasks/check-if-already-published.js @@ -46,7 +46,7 @@ export default class CheckIfAlreadyPublished extends Task { let localHash; try { - const localFiles = [join(path, './eik.json')]; + const localFiles = [join(path, 'eik.json')]; if (files) { const mappings = await this.config.mappings(); diff --git a/classes/publish/package/tasks/cleanup.js b/classes/publish/package/tasks/cleanup.js index 46e6e71c..2e3cbdd3 100644 --- a/classes/publish/package/tasks/cleanup.js +++ b/classes/publish/package/tasks/cleanup.js @@ -1,6 +1,7 @@ -import { join } from 'path'; -import fs from 'fs'; -import { rimrafSync } from 'rimraf'; +import { join } from 'node:path'; +import { existsSync } from 'node:fs'; +import { readdir } from 'node:fs/promises'; +import { rimraf } from 'rimraf'; import Task from './task.js'; export default class Cleanup extends Task { @@ -8,10 +9,13 @@ export default class Cleanup extends Task { const { log, path } = this; log.debug('Cleaning up'); - if (fs.existsSync(path)) { - fs.readdirSync(path) - .filter((file) => file !== 'integrity.json') - .forEach((file) => rimrafSync(join(path, file))); + if (existsSync(path)) { + const dir = await readdir(path); + await Promise.all( + dir + .filter((file) => file !== 'integrity.json') + .map((file) => rimraf(join(path, file))), + ); } } } diff --git a/classes/publish/package/tasks/create-zip-file.js b/classes/publish/package/tasks/create-zip-file.js index ef2b2136..fb29c142 100644 --- a/classes/publish/package/tasks/create-zip-file.js +++ b/classes/publish/package/tasks/create-zip-file.js @@ -10,13 +10,13 @@ export default class CreateZipFile extends Task { const { log, path } = this; const { name, map, server, out, files } = this.config; - log.debug(`Creating zip file`); - log.debug(` ==> ${join(path, `eik.tgz`)}`); + log.debug('Creating zip file'); + log.debug(` ==> ${join(path, 'eik.tgz')}`); const filesToZip = []; try { - const eikPathDest = join(path, './eik.json'); + const eikPathDest = join(path, 'eik.json'); writeFileSync( eikPathDest, JSON.stringify( @@ -59,7 +59,7 @@ export default class CreateZipFile extends Task { } try { - const zipFile = resolve(`${path}/eik.tgz`); + const zipFile = resolve(path, 'eik.tgz'); await tar.c( { diff --git a/classes/publish/package/tasks/upload-files.js b/classes/publish/package/tasks/upload-files.js index ef33d8ae..f50a3ec5 100644 --- a/classes/publish/package/tasks/upload-files.js +++ b/classes/publish/package/tasks/upload-files.js @@ -1,6 +1,7 @@ -import { join } from 'path'; import { request } from '../../../../utils/http/index.js'; import { typeSlug } from '../../../../utils/index.js'; +import { joinUrlPathname } from '../../../../utils/url.js'; + import Task from './task.js'; export default class UploadFiles extends Task { @@ -9,7 +10,7 @@ export default class UploadFiles extends Task { const { server, name, version, type, token } = this.config; log.debug('Uploading zip file to server'); try { - const pathname = join( + const pathname = joinUrlPathname( typeSlug(type), encodeURIComponent(name), version, diff --git a/classes/version.js b/classes/version.js index 49e94341..b74995d2 100644 --- a/classes/version.js +++ b/classes/version.js @@ -124,7 +124,7 @@ export default class Version { let localHash; try { makeDirectorySync(path); - const eikPathDest = join(path, './eik.json'); + const eikPathDest = join(path, 'eik.json'); const eikJSON = { name, server, diff --git a/package.json b/package.json index aae3a475..5c5d0473 100644 --- a/package.json +++ b/package.json @@ -25,10 +25,6 @@ "test:integration": "cross-env HTTP_PORT=0 LOG_LEVEL=fatal tap --timeout 0 --disable-coverage test/integration/**/*.test.mjs", "test:unit": "cross-env HTTP_PORT=0 LOG_LEVEL=fatal tap --timeout 0 --disable-coverage test/*.test.mjs", "test:tasks": "cross-env HTTP_PORT=0 LOG_LEVEL=fatal tap --timeout 0 --disable-coverage test/tasks/*.test.mjs", - "test:ci:integration": "npm run test:integration -- --jobs=1", - "test:ci:unit": "npm run test:unit -- --jobs=1", - "test:ci:tasks": "npm run test:tasks -- --jobs=1", - "test:ci": "run-s test:ci:*", "lint": "eslint .", "lint:fix": "eslint --fix .", "format:check": "prettier -c .", @@ -62,7 +58,7 @@ "devDependencies": { "@eik/eslint-config": "1.0.2", "@eik/semantic-release-config": "1.0.0", - "@eik/service": "2.3.0", + "@eik/service": "2.3.1", "@eik/sink-memory": "1.1.2", "@eik/typescript-config": "1.0.0", "cross-env": "7.0.3", diff --git a/test/integration/alias-legacy.test.mjs b/test/integration/alias-legacy.test.mjs index e09ea608..7aea134d 100644 --- a/test/integration/alias-legacy.test.mjs +++ b/test/integration/alias-legacy.test.mjs @@ -31,7 +31,7 @@ beforeEach(async (t) => { port: 0, }); const folder = await fs.mkdtemp(join(os.tmpdir(), basename(__filename))); - const eik = join(__dirname, '../../index.js'); + const eik = join(__dirname, '..', '..', 'index.js'); const token = await cli.login({ server: address, @@ -44,14 +44,14 @@ beforeEach(async (t) => { type: 'npm', server: address, files: { - 'index.js': join(__dirname, './../fixtures/client.js'), - 'index.css': join(__dirname, './../fixtures/styles.css'), + 'index.js': join(__dirname, '..', 'fixtures', 'client.js'), + 'index.css': join(__dirname, '..', 'fixtures', 'styles.css'), }, }; await fs.writeFile(join(folder, 'eik.json'), JSON.stringify(assets)); - const cmd = `${eik} package --token ${token} --cwd ${folder}`; + const cmd = `node ${eik} package --token ${token} --cwd ${folder}`; await exec(cmd); const map = { @@ -63,7 +63,7 @@ beforeEach(async (t) => { }, }; await fs.writeFile(join(folder, 'import-map.json'), JSON.stringify(map)); - const mapCmd = `${eik} map test-map 1.0.0 import-map.json + const mapCmd = `node ${eik} map test-map 1.0.0 import-map.json --token ${token} --server ${address} --cwd ${folder}`; @@ -81,24 +81,24 @@ afterEach(async (t) => { test('eik package-alias ', async (t) => { const { address, token, folder: cwd } = t.context; - const eik = join(__dirname, '../../index.js'); + const eik = join(__dirname, '..', '..', 'index.js'); const assets = { server: address, name: 'my-pack', version: '1.0.0', files: { - 'index.js': join(__dirname, '../fixtures/client.js'), - 'index.css': join(__dirname, '../fixtures/styles.css'), + 'index.js': join(__dirname, '..', 'fixtures', 'client.js'), + 'index.css': join(__dirname, '..', 'fixtures', 'styles.css'), }, }; await fs.writeFile(join(cwd, 'eik.json'), JSON.stringify(assets)); - const cmd1 = `${eik} package --token ${token} --cwd ${cwd}`; + const cmd1 = `node ${eik} package --token ${token} --cwd ${cwd}`; await exec(cmd1); - const cmd2 = `${eik} package-alias my-pack 1.0.0 1 + const cmd2 = `node ${eik} package-alias my-pack 1.0.0 1 --token ${token} --server ${address} --cwd ${cwd}`; @@ -117,8 +117,8 @@ test('eik package-alias ', async (t) => { }); test('eik npm-alias --token --server : no eik.json or .eikrc', async (t) => { - const eik = join(__dirname, '../../index.js'); - const cmd = `${eik} npm-alias scroll-into-view-if-needed 2.2.24 2 + const eik = join(__dirname, '..', '..', 'index.js'); + const cmd = `node ${eik} npm-alias scroll-into-view-if-needed 2.2.24 2 --token ${t.context.token} --server ${t.context.address} --cwd ${t.context.folder}`; @@ -148,16 +148,16 @@ test('eik npm-alias : publish details provided by eik.j version: '1.0.0', server: t.context.address, files: { - 'index.js': join(__dirname, './../fixtures/client.js'), - 'index.css': join(__dirname, './../fixtures/styles.css'), + 'index.js': join(__dirname, '..', 'fixtures', 'client.js'), + 'index.css': join(__dirname, '..', 'fixtures', 'styles.css'), }, }; await fs.writeFile( join(t.context.folder, 'eik.json'), JSON.stringify(assets), ); - const eik = join(__dirname, '../../index.js'); - const cmd = `${eik} npm-alias scroll-into-view-if-needed 2.2.24 2 --token ${t.context.token} --cwd ${t.context.folder}`; + const eik = join(__dirname, '..', '..', 'index.js'); + const cmd = `node ${eik} npm-alias scroll-into-view-if-needed 2.2.24 2 --token ${t.context.token} --cwd ${t.context.folder}`; const { error, stdout } = await exec(cmd); @@ -179,8 +179,8 @@ test('eik npm-alias : publish details provided by eik.j }); test('eik map-alias --token --server : no eik.json or .eikrc', async (t) => { - const eik = join(__dirname, '../../index.js'); - const cmd = `${eik} map-alias test-map 1.0.0 1 + const eik = join(__dirname, '..', '..', 'index.js'); + const cmd = `node ${eik} map-alias test-map 1.0.0 1 --token ${t.context.token} --server ${t.context.address} --cwd ${t.context.folder}`; @@ -206,16 +206,16 @@ test('eik map-alias : publish details provided by eik.j version: '1.0.0', server: t.context.address, files: { - 'index.js': join(__dirname, './../fixtures/client.js'), - 'index.css': join(__dirname, './../fixtures/styles.css'), + 'index.js': join(__dirname, '..', 'fixtures', 'client.js'), + 'index.css': join(__dirname, '..', 'fixtures', 'styles.css'), }, }; await fs.writeFile( join(t.context.folder, 'eik.json'), JSON.stringify(assets), ); - const eik = join(__dirname, '../../index.js'); - const cmd = `${eik} map-alias test-map 1.0.0 1 --token ${t.context.token} --cwd ${t.context.folder}`; + const eik = join(__dirname, '..', '..', 'index.js'); + const cmd = `node ${eik} map-alias test-map 1.0.0 1 --token ${t.context.token} --cwd ${t.context.folder}`; const { error, stdout } = await exec(cmd); diff --git a/test/integration/alias.test.mjs b/test/integration/alias.test.mjs index af5a5f0e..dedf1541 100644 --- a/test/integration/alias.test.mjs +++ b/test/integration/alias.test.mjs @@ -31,7 +31,7 @@ beforeEach(async (t) => { port: 0, }); const folder = await fs.mkdtemp(join(os.tmpdir(), basename(__filename))); - const eik = join(__dirname, '../../index.js'); + const eik = join(__dirname, '..', '..', 'index.js'); const token = await cli.login({ server: address, @@ -44,14 +44,14 @@ beforeEach(async (t) => { type: 'npm', server: address, files: { - 'index.js': join(__dirname, './../fixtures/client.js'), - 'index.css': join(__dirname, './../fixtures/styles.css'), + 'index.js': join(__dirname, '..', 'fixtures', 'client.js'), + 'index.css': join(__dirname, '..', 'fixtures', 'styles.css'), }, }; await fs.writeFile(join(folder, 'eik.json'), JSON.stringify(assets)); - const cmd = `${eik} package --token ${token} --cwd ${folder}`; + const cmd = `node ${eik} package --token ${token} --cwd ${folder}`; await exec(cmd); const map = { @@ -63,7 +63,7 @@ beforeEach(async (t) => { }, }; await fs.writeFile(join(folder, 'import-map.json'), JSON.stringify(map)); - const mapCmd = `${eik} map test-map 1.0.0 import-map.json + const mapCmd = `node ${eik} map test-map 1.0.0 import-map.json --token ${token} --server ${address} --cwd ${folder}`; @@ -81,7 +81,7 @@ afterEach(async (t) => { test('packages: eik alias ', async (t) => { const { address, token, folder: cwd } = t.context; - const eik = join(__dirname, '../../index.js'); + const eik = join(__dirname, '..', '..', 'index.js'); const assets = { server: address, @@ -89,17 +89,17 @@ test('packages: eik alias ', async (t) => { name: 'my-pack', version: '1.0.0', files: { - 'index.js': join(__dirname, '../fixtures/client.js'), - 'index.css': join(__dirname, '../fixtures/styles.css'), + 'index.js': join(__dirname, '..', 'fixtures', 'client.js'), + 'index.css': join(__dirname, '..', 'fixtures', 'styles.css'), }, }; await fs.writeFile(join(cwd, 'eik.json'), JSON.stringify(assets)); - const cmd1 = `${eik} package --token ${token} --cwd ${cwd}`; + const cmd1 = `node ${eik} package --token ${token} --cwd ${cwd}`; await exec(cmd1); - const cmd2 = `${eik} alias my-pack 1.0.0 1 + const cmd2 = `node ${eik} alias my-pack 1.0.0 1 --token ${token} --server ${address} --cwd ${cwd}`; @@ -118,8 +118,8 @@ test('packages: eik alias ', async (t) => { }); test('npm: eik alias --token --server : no eik.json or .eikrc', async (t) => { - const eik = join(__dirname, '../../index.js'); - const cmd = `${eik} npm-alias scroll-into-view-if-needed 2.2.24 2 + const eik = join(__dirname, '..', '..', 'index.js'); + const cmd = `node ${eik} npm-alias scroll-into-view-if-needed 2.2.24 2 --token ${t.context.token} --type npm --server ${t.context.address} @@ -151,16 +151,16 @@ test('npm: eik alias : publish details provided by eik. version: '1.0.0', server: t.context.address, files: { - 'index.js': join(__dirname, './../fixtures/client.js'), - 'index.css': join(__dirname, './../fixtures/styles.css'), + 'index.js': join(__dirname, '..', 'fixtures', 'client.js'), + 'index.css': join(__dirname, '..', 'fixtures', 'styles.css'), }, }; await fs.writeFile( join(t.context.folder, 'eik.json'), JSON.stringify(assets), ); - const eik = join(__dirname, '../../index.js'); - const cmd = `${eik} alias scroll-into-view-if-needed 2.2.24 2 --token ${t.context.token} --cwd ${t.context.folder}`; + const eik = join(__dirname, '..', '..', 'index.js'); + const cmd = `node ${eik} alias scroll-into-view-if-needed 2.2.24 2 --token ${t.context.token} --cwd ${t.context.folder}`; const { error, stdout } = await exec(cmd); @@ -182,8 +182,8 @@ test('npm: eik alias : publish details provided by eik. }); test('map: eik alias --token --server : no eik.json or .eikrc', async (t) => { - const eik = join(__dirname, '../../index.js'); - const cmd = `${eik} map-alias test-map 1.0.0 1 + const eik = join(__dirname, '..', '..', 'index.js'); + const cmd = `node ${eik} map-alias test-map 1.0.0 1 --token ${t.context.token} --type map --server ${t.context.address} @@ -211,16 +211,16 @@ test('map: eik alias : publish details provided by eik. version: '1.0.0', server: t.context.address, files: { - 'index.js': join(__dirname, './../fixtures/client.js'), - 'index.css': join(__dirname, './../fixtures/styles.css'), + 'index.js': join(__dirname, '..', 'fixtures', 'client.js'), + 'index.css': join(__dirname, '..', 'fixtures', 'styles.css'), }, }; await fs.writeFile( join(t.context.folder, 'eik.json'), JSON.stringify(assets), ); - const eik = join(__dirname, '../../index.js'); - const cmd = `${eik} alias test-map 1.0.0 1 --token ${t.context.token} --cwd ${t.context.folder}`; + const eik = join(__dirname, '..', '..', 'index.js'); + const cmd = `node ${eik} alias test-map 1.0.0 1 --token ${t.context.token} --cwd ${t.context.folder}`; const { error, stdout } = await exec(cmd); diff --git a/test/integration/init.test.mjs b/test/integration/init.test.mjs index e9a1e0ce..0f766c4f 100644 --- a/test/integration/init.test.mjs +++ b/test/integration/init.test.mjs @@ -24,9 +24,9 @@ function exec(cmd) { } test('Initializing a new eik.json file', async (t) => { - const eik = join(__dirname, '../../index.js'); + const eik = join(__dirname, '..', '../index.js'); const folder = await fs.mkdtemp(join(os.tmpdir(), basename(__filename))); - const publishCmd = `${eik} init --cwd ${folder}`; + const publishCmd = `node ${eik} init --cwd ${folder}`; await exec(publishCmd); @@ -41,9 +41,9 @@ test('Initializing a new eik.json file', async (t) => { }); test('Initializing a new eik.json file passing custom values', async (t) => { - const eik = join(__dirname, '../../index.js'); + const eik = join(__dirname, '..', '../index.js'); const folder = await fs.mkdtemp(join(os.tmpdir(), basename(__filename))); - const publishCmd = `${eik} init + const publishCmd = `node ${eik} init --cwd ${folder} --name custom-name --version 2.0.0 @@ -62,7 +62,7 @@ test('Initializing a new eik.json file passing custom values', async (t) => { }); test('Initializing a new eik.json file in an existing project', async (t) => { - const eik = join(__dirname, '../../index.js'); + const eik = join(__dirname, '..', '..', 'index.js'); const folder = await fs.mkdtemp(join(os.tmpdir(), basename(__filename))); const packageJson = { @@ -76,7 +76,7 @@ test('Initializing a new eik.json file in an existing project', async (t) => { 'utf-8', ); - const publishCmd = `${eik} init --cwd ${folder}`; + const publishCmd = `node ${eik} init --cwd ${folder}`; await exec(publishCmd); const eikJson = JSON.parse( diff --git a/test/integration/integrity.test.mjs b/test/integration/integrity.test.mjs index 2cbf62bf..a39c2210 100644 --- a/test/integration/integrity.test.mjs +++ b/test/integration/integrity.test.mjs @@ -2,7 +2,7 @@ import fastify from 'fastify'; import { promises as fs } from 'fs'; import os from 'os'; import { exec as execCallback } from 'child_process'; -import { join, basename } from 'path'; +import { join, basename, sep } from 'path'; import { test, beforeEach, afterEach } from 'tap'; import EikService from '@eik/service'; import Sink from '@eik/sink-memory'; @@ -53,8 +53,8 @@ test('eik meta : details provided by eik.json', async (t) => { version: '1.0.0', server: t.context.address, files: { - 'index.js': join(__dirname, './../fixtures/client.js'), - 'index.css': join(__dirname, './../fixtures/styles.css'), + 'index.js': join(__dirname, '..', 'fixtures/client.js'), + 'index.css': join(__dirname, '../fixtures/styles.css'), }, }; await fs.writeFile( @@ -62,18 +62,18 @@ test('eik meta : details provided by eik.json', async (t) => { JSON.stringify(assets), ); - const eik = join(__dirname, '../../index.js'); + const eik = join(__dirname, '..', '..', 'index.js'); - let cmd = `${eik} package --token ${t.context.token} --cwd ${t.context.folder}`; + let cmd = `node ${eik} package --token ${t.context.token} --cwd ${t.context.folder}`; await exec(cmd); - cmd = `${eik} integrity --cwd ${t.context.folder}`; + cmd = `node ${eik} integrity --cwd ${t.context.folder}`; const { error, stdout } = await exec(cmd); const integrity = JSON.parse( await fs.readFile( - join(t.context.folder, './.eik/integrity.json'), + join(t.context.folder, '.eik', 'integrity.json'), 'utf8', ), ); @@ -81,7 +81,7 @@ test('eik meta : details provided by eik.json', async (t) => { t.notOk(error); t.match( stdout, - 'integrity information for package "test-app" (v1.0.0) saved to ".eik/integrity.json"', + `integrity information for package "test-app" (v1.0.0) saved to ".eik${sep}integrity.json"`, ); t.equal(integrity.name, 'test-app'); t.equal(integrity.version, '1.0.0'); @@ -96,8 +96,8 @@ test('eik meta : details provided by eik.json - npm namespace', async (t) => { type: 'npm', server: t.context.address, files: { - 'index.js': join(__dirname, './../fixtures/client.js'), - 'index.css': join(__dirname, './../fixtures/styles.css'), + 'index.js': join(__dirname, '..', 'fixtures', 'client.js'), + 'index.css': join(__dirname, '..', 'fixtures', 'styles.css'), }, }; await fs.writeFile( @@ -105,17 +105,17 @@ test('eik meta : details provided by eik.json - npm namespace', async (t) => { JSON.stringify(assets), ); - const eik = join(__dirname, '../../index.js'); + const eik = join(__dirname, '..', '../index.js'); - let cmd = `${eik} package --token ${t.context.token} --cwd ${t.context.folder}`; + let cmd = `node ${eik} package --token ${t.context.token} --cwd ${t.context.folder}`; await exec(cmd); - cmd = `${eik} integrity --cwd ${t.context.folder}`; + cmd = `node ${eik} integrity --cwd ${t.context.folder}`; const { error, stdout } = await exec(cmd); const integrity = JSON.parse( await fs.readFile( - join(t.context.folder, './.eik/integrity.json'), + join(t.context.folder, '.eik', 'integrity.json'), 'utf8', ), ); @@ -123,7 +123,7 @@ test('eik meta : details provided by eik.json - npm namespace', async (t) => { t.notOk(error); t.match( stdout, - 'integrity information for package "test-app-npm" (v1.0.0) saved to ".eik/integrity.json"', + `integrity information for package "test-app-npm" (v1.0.0) saved to ".eik${sep}integrity.json"`, ); t.equal(integrity.name, 'test-app-npm'); t.equal(integrity.version, '1.0.0'); diff --git a/test/integration/login.test.mjs b/test/integration/login.test.mjs index 36f545bd..d4c59b3d 100644 --- a/test/integration/login.test.mjs +++ b/test/integration/login.test.mjs @@ -42,8 +42,8 @@ afterEach(async (t) => { }); test('eik login --key --server --cwd : valid key', async (t) => { - const eik = join(__dirname, '../../index.js'); - const cmd = `${eik} login --key change_me --server ${t.context.address} --cwd ${t.context.folder}`; + const eik = join(__dirname, '..', '../index.js'); + const cmd = `node ${eik} login --key change_me --server ${t.context.address} --cwd ${t.context.folder}`; const { stdout } = await exec(cmd); @@ -52,8 +52,8 @@ test('eik login --key --server --cwd : valid key', async (t) => { }); test('eik login --key --server --cwd : invalid key', async (t) => { - const eik = join(__dirname, '../../index.js'); - const cmd = `${eik} login --key invalid --server ${t.context.address} --cwd ${t.context.folder}`; + const eik = join(__dirname, '..', '..', 'index.js'); + const cmd = `node ${eik} login --key invalid --server ${t.context.address} --cwd ${t.context.folder}`; const { stdout } = await exec(cmd); t.match(stdout, 'Login unsuccessful'); diff --git a/test/integration/map.test.mjs b/test/integration/map.test.mjs index ca56f686..bd35179c 100644 --- a/test/integration/map.test.mjs +++ b/test/integration/map.test.mjs @@ -53,8 +53,8 @@ test('eik map : publish, details provided by eik.json file', async (t) => { version: '2.2.24', server: t.context.address, files: { - 'index.js': join(__dirname, './../fixtures/client.js'), - 'index.css': join(__dirname, './../fixtures/styles.css'), + 'index.js': join(__dirname, '..', 'fixtures', 'client.js'), + 'index.css': join(__dirname, '..', 'fixtures', 'styles.css'), }, }; await fs.writeFile( @@ -75,8 +75,8 @@ test('eik map : publish, details provided by eik.json file', async (t) => { JSON.stringify(map), ); - const eik = join(__dirname, '../../index.js'); - const cmd = `${eik} map test-map 1.0.0 import-map.json --token ${t.context.token} --cwd ${t.context.folder}`; + const eik = join(__dirname, '..', '..', 'index.js'); + const cmd = `node ${eik} map test-map 1.0.0 import-map.json --token ${t.context.token} --cwd ${t.context.folder}`; const { error, stdout } = await exec(cmd); diff --git a/test/integration/meta.test.mjs b/test/integration/meta.test.mjs index eb273b75..e91c39b7 100644 --- a/test/integration/meta.test.mjs +++ b/test/integration/meta.test.mjs @@ -31,7 +31,7 @@ beforeEach(async (t) => { port: 0, }); const folder = await fs.mkdtemp(join(os.tmpdir(), basename(__filename))); - const eik = join(__dirname, '../../index.js'); + const eik = join(__dirname, '..', '..', 'index.js'); const token = await cli.login({ server: address, @@ -44,14 +44,14 @@ beforeEach(async (t) => { type: 'npm', server: address, files: { - 'index.js': join(__dirname, './../fixtures/client.js'), - 'index.css': join(__dirname, './../fixtures/styles.css'), + 'index.js': join(__dirname, '..', 'fixtures', 'client.js'), + 'index.css': join(__dirname, '..', 'fixtures', 'styles.css'), }, }; await fs.writeFile(join(folder, 'eik.json'), JSON.stringify(assets)); - const cmd = `${eik} package --token ${token} --cwd ${folder}`; + const cmd = `node ${eik} package --token ${token} --cwd ${folder}`; await exec(cmd); t.context.server = server; @@ -65,8 +65,8 @@ afterEach(async (t) => { }); test('eik meta', async (t) => { - const eik = join(__dirname, '../../index.js'); - const cmd = `${eik} meta scroll-into-view-if-needed --cwd ${t.context.folder}`; + const eik = join(__dirname, '..', '..', 'index.js'); + const cmd = `node ${eik} meta scroll-into-view-if-needed --cwd ${t.context.folder}`; const { error, stdout } = await exec(cmd); diff --git a/test/integration/package.test.mjs b/test/integration/package.test.mjs index a438dc60..e425282e 100644 --- a/test/integration/package.test.mjs +++ b/test/integration/package.test.mjs @@ -53,8 +53,8 @@ test('eik package : package, details provided by eik.json file', async (t) => { version: '1.0.0', server: t.context.address, files: { - 'index.js': join(__dirname, './../fixtures/client.js'), - 'index.css': join(__dirname, './../fixtures/styles.css'), + 'index.js': join(__dirname, '..', 'fixtures', 'client.js'), + 'index.css': join(__dirname, '..', 'fixtures', 'styles.css'), }, }; @@ -63,8 +63,8 @@ test('eik package : package, details provided by eik.json file', async (t) => { JSON.stringify(assets), ); - const eik = join(__dirname, '../../index.js'); - const cmd = `${eik} package --token ${t.context.token} --cwd ${t.context.folder}`; + const eik = join(__dirname, '..', '..', 'index.js'); + const cmd = `node ${eik} package --token ${t.context.token} --cwd ${t.context.folder}`; const { error, stdout } = await exec(cmd); @@ -87,8 +87,8 @@ test('eik package : package, details provided by eik.json file - npm namespace', type: 'npm', server: t.context.address, files: { - 'index.js': join(__dirname, './../fixtures/client.js'), - 'index.css': join(__dirname, './../fixtures/styles.css'), + 'index.js': join(__dirname, '..', 'fixtures', 'client.js'), + 'index.css': join(__dirname, '..', 'fixtures', 'styles.css'), }, }; @@ -97,8 +97,8 @@ test('eik package : package, details provided by eik.json file - npm namespace', JSON.stringify(assets), ); - const eik = join(__dirname, '../../index.js'); - const cmd = `${eik} package --token ${t.context.token} --cwd ${t.context.folder} --npm`; + const eik = join(__dirname, '..', '..', 'index.js'); + const cmd = `node ${eik} package --token ${t.context.token} --cwd ${t.context.folder} --npm`; const { error, stdout } = await exec(cmd); @@ -121,8 +121,8 @@ test('eik package : package, details provided by eik.json file - explicit packag type: 'package', server: t.context.address, files: { - 'index.js': join(__dirname, './../fixtures/client.js'), - 'index.css': join(__dirname, './../fixtures/styles.css'), + 'index.js': join(__dirname, '..', 'fixtures', 'client.js'), + 'index.css': join(__dirname, '..', 'fixtures', 'styles.css'), }, }; @@ -131,8 +131,8 @@ test('eik package : package, details provided by eik.json file - explicit packag JSON.stringify(assets), ); - const eik = join(__dirname, '../../index.js'); - const cmd = `${eik} package --token ${t.context.token} --cwd ${t.context.folder} --npm`; + const eik = join(__dirname, '..', '..', 'index.js'); + const cmd = `node ${eik} package --token ${t.context.token} --cwd ${t.context.folder} --npm`; const { error, stdout } = await exec(cmd); @@ -155,8 +155,8 @@ test('eik package : package, details provided by package.json values', async (t) eik: { server: t.context.address, files: { - 'index.js': join(__dirname, './../fixtures/client.js'), - 'index.css': join(__dirname, './../fixtures/styles.css'), + 'index.js': join(__dirname, '..', 'fixtures', 'client.js'), + 'index.css': join(__dirname, '..', 'fixtures', 'styles.css'), }, }, }; @@ -166,8 +166,8 @@ test('eik package : package, details provided by package.json values', async (t) JSON.stringify(assets), ); - const eik = join(__dirname, '../../index.js'); - const cmd = `${eik} package --token ${t.context.token} --cwd ${t.context.folder}`; + const eik = join(__dirname, '..', '..', 'index.js'); + const cmd = `node ${eik} package --token ${t.context.token} --cwd ${t.context.folder}`; const { error, stdout } = await exec(cmd); @@ -190,8 +190,8 @@ test('eik package : package, details provided by package.json values and eik.jso eik: { server: t.context.address, files: { - 'index.js': join(__dirname, './../fixtures/client.js'), - 'index.css': join(__dirname, './../fixtures/styles.css'), + 'index.js': join(__dirname, '..', 'fixtures', 'client.js'), + 'index.css': join(__dirname, '..', 'fixtures', 'styles.css'), }, }, }; @@ -206,8 +206,8 @@ test('eik package : package, details provided by package.json values and eik.jso version: '1.0.0', server: t.context.address, files: { - 'index.js': join(__dirname, './../fixtures/client.js'), - 'index.css': join(__dirname, './../fixtures/styles.css'), + 'index.js': join(__dirname, '..', 'fixtures', 'client.js'), + 'index.css': join(__dirname, '..', 'fixtures', 'styles.css'), }, }; @@ -216,8 +216,8 @@ test('eik package : package, details provided by package.json values and eik.jso JSON.stringify(assets), ); - const eik = join(__dirname, '../../index.js'); - const cmd = `${eik} package --token ${t.context.token} --cwd ${t.context.folder}`; + const eik = join(__dirname, '..', '..', 'index.js'); + const cmd = `node ${eik} package --token ${t.context.token} --cwd ${t.context.folder}`; const { error } = await exec(cmd); @@ -226,7 +226,7 @@ test('eik package : package, details provided by package.json values and eik.jso }); test('workflow: publish npm, alias npm, publish map, alias map and then publish package using map', async (t) => { - const eik = join(__dirname, '../../index.js'); + const eik = join(__dirname, '..', '..', 'index.js'); let cmd = ''; // publish npm dep @@ -235,8 +235,8 @@ test('workflow: publish npm, alias npm, publish map, alias map and then publish version: '2.2.24', server: t.context.address, files: { - 'index.js': join(__dirname, './../fixtures/client.js'), - 'index.css': join(__dirname, './../fixtures/styles.css'), + 'index.js': join(__dirname, '..', 'fixtures', 'client.js'), + 'index.css': join(__dirname, '..', 'fixtures', 'styles.css'), }, }; @@ -245,11 +245,11 @@ test('workflow: publish npm, alias npm, publish map, alias map and then publish JSON.stringify(assets), ); - cmd = `${eik} package --token ${t.context.token} --cwd ${t.context.folder} --npm`; + cmd = `node ${eik} package --token ${t.context.token} --cwd ${t.context.folder} --npm`; await exec(cmd); // alias npm dependency - cmd = `${eik} npm-alias scroll-into-view-if-needed 2.2.24 2 + cmd = `node ${eik} npm-alias scroll-into-view-if-needed 2.2.24 2 --token ${t.context.token} --server ${t.context.address}`; await exec(cmd.split('\n').join(' ')); @@ -269,14 +269,14 @@ test('workflow: publish npm, alias npm, publish map, alias map and then publish ); // upload import map file - cmd = `${eik} map my-map 1.0.0 ./import-map.json + cmd = `node ${eik} map my-map 1.0.0 ./import-map.json --cwd ${t.context.folder} --token ${t.context.token} --server ${t.context.address}`; await exec(cmd.split('\n').join(' ')); // alias import map - cmd = `${eik} map-alias my-map 1.0.0 1 + cmd = `node ${eik} map-alias my-map 1.0.0 1 --token ${t.context.token} --server ${t.context.address}`; await exec(cmd.split('\n').join(' ')); @@ -288,9 +288,11 @@ test('workflow: publish npm, alias npm, publish map, alias map and then publish files: { 'index.js': join( __dirname, - './../fixtures/client-with-bare-imports.js', + '..', + 'fixtures', + 'client-with-bare-imports.js', ), - 'index.css': join(__dirname, './../fixtures/styles.css'), + 'index.css': join(__dirname, '..', 'fixtures', 'styles.css'), }, 'import-map': [new URL('/map/my-map/v1', t.context.address).href], }; @@ -302,7 +304,7 @@ test('workflow: publish npm, alias npm, publish map, alias map and then publish // TODO: create a bundle that uses import maps // use import map when publishing app files - // cmd = `${eik} package + // cmd = `node ${eik} package // --token ${t.context.token} // --cwd ${t.context.folder} // --debug`; diff --git a/utils/url.js b/utils/url.js new file mode 100644 index 00000000..cc90b20a --- /dev/null +++ b/utils/url.js @@ -0,0 +1,10 @@ +import { join } from 'node:path'; + +/** + * A version of path.join that replaces \ (win32) with / + * @param {...string} parts + * @returns {string} + */ +export function joinUrlPathname(...parts) { + return join(...parts).replace(/\\/g, '/'); +}