Skip to content
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

fix: add support for Windows #584

Merged
merged 6 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

- run: npm run types

- run: npm run test:ci
- run: npm test

- run: npx semantic-release
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -30,4 +30,4 @@ jobs:

- run: npm run types

- run: npm run test:ci
- run: npm test
8 changes: 6 additions & 2 deletions classes/alias.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions classes/integrity.js
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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}`);
Expand Down
9 changes: 6 additions & 3 deletions classes/meta.js
Original file line number Diff line number Diff line change
@@ -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'];

Expand Down Expand Up @@ -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));
}
Expand All @@ -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,
);

Expand Down
3 changes: 2 additions & 1 deletion classes/publish/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
18 changes: 11 additions & 7 deletions classes/publish/package/tasks/cleanup.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
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 {
async process() {
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))),
);
}
}
}
8 changes: 4 additions & 4 deletions classes/publish/package/tasks/create-zip-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
{
Expand Down
5 changes: 3 additions & 2 deletions classes/publish/package/tasks/upload-files.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion classes/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down Expand Up @@ -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",
Expand Down
44 changes: 22 additions & 22 deletions test/integration/alias-legacy.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = {
Expand All @@ -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}`;
Expand All @@ -81,24 +81,24 @@ afterEach(async (t) => {

test('eik package-alias <name> <version> <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}`;
Expand All @@ -117,8 +117,8 @@ test('eik package-alias <name> <version> <alias>', async (t) => {
});

test('eik npm-alias <name> <version> <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}`;
Expand Down Expand Up @@ -148,16 +148,16 @@ test('eik npm-alias <name> <version> <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);

Expand All @@ -179,8 +179,8 @@ test('eik npm-alias <name> <version> <alias> : publish details provided by eik.j
});

test('eik map-alias <name> <version> <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}`;
Expand All @@ -206,16 +206,16 @@ test('eik map-alias <name> <version> <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);

Expand Down
Loading