Skip to content

Commit

Permalink
chore: upgrade common to version 4
Browse files Browse the repository at this point in the history
  • Loading branch information
trygvea committed Jun 30, 2023
1 parent 7a82ce8 commit 58046d2
Show file tree
Hide file tree
Showing 4 changed files with 250 additions and 169 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
},
"homepage": "https://github.com/eik-lib/node-client#readme",
"dependencies": {
"@eik/common": "3.0.1",
"@eik/common-schemas": "4.0.0-next.11",
"@eik/common-utils": "4.0.0-next.11",
"@eik/common-config-loader": "4.0.0-next.11",
"abslog": "2.4.0",
"undici": "5.22.1"
},
Expand Down
7 changes: 1 addition & 6 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
export default {
input: 'src/index.js',
external: [
'@eik/common',
'undici',
'abslog',
'path',
],
external: ['@eik/common-config-loader', 'undici', 'abslog', 'path'],
output: [
{
exports: 'auto',
Expand Down
26 changes: 14 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { helpers } from '@eik/common';
import { getDefaults } from '@eik/common-config-loader';
import { request } from 'undici';
import { join } from 'path';
import Asset from './asset.js';

const trimSlash = (value = '') => {
if (value.endsWith('/')) return value.substring(0, value.length - 1);
return value;
}
};

const fetchImportMaps = async (urls = []) => {
try{
try {
const maps = urls.map(async (map) => {
const {
statusCode,
body
} = await request(map, { maxRedirections: 2 });

const { statusCode, body } = await request(map, {
maxRedirections: 2,
});

if (statusCode === 404) {
throw new Error('Import map could not be found on server');
} else if (statusCode >= 400 && statusCode < 500) {
Expand All @@ -31,7 +30,7 @@ const fetchImportMaps = async (urls = []) => {
`Unable to load import map file from server: ${err.message}`,
);
}
}
};

export default class NodeClient {
#development;
Expand All @@ -55,7 +54,7 @@ export default class NodeClient {
}

async load() {
this.#config = await helpers.getDefaults(this.#path);
this.#config = await getDefaults(this.#path);
if (this.#loadMaps) {
this.#maps = await fetchImportMaps(this.#config.map);
}
Expand Down Expand Up @@ -83,7 +82,8 @@ export default class NodeClient {
}

get pathname() {
if (this.#config.type && this.#config.name && this.#config.version) return join('/', this.type, this.name, this.version);
if (this.#config.type && this.#config.name && this.#config.version)
return join('/', this.type, this.name, this.version);
throw new Error('Eik config was not loaded before calling .pathname');
}

Expand All @@ -101,6 +101,8 @@ export default class NodeClient {

maps() {
if (this.#config.version && this.#loadMaps) return this.#maps;
throw new Error('Eik config was not loaded or "loadMaps" is "false" when calling .maps()');
throw new Error(
'Eik config was not loaded or "loadMaps" is "false" when calling .maps()',
);
}
}
Loading

0 comments on commit 58046d2

Please sign in to comment.