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

Next #103

Open
wants to merge 65 commits into
base: main
Choose a base branch
from
Open

Next #103

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
559294c
feat: Rework module to suite current functionality of Eik
Mar 10, 2021
288ffec
test: lint love
Mar 10, 2021
9223c61
ci: fix ci tests
Mar 10, 2021
70ac9e0
Merge pull request #11 from eik-lib/rework
trygve-lie Mar 10, 2021
c6600d9
ci: Treat release config as a common.js file
Mar 10, 2021
06fa48a
Merge pull request #12 from eik-lib/release
trygve-lie Mar 10, 2021
17be953
chore(release): 1.0.0-next.1 [skip ci]
semantic-release-bot Mar 10, 2021
f3d8c73
chore: Rename module to @eik/node-client
Mar 10, 2021
015aba1
Merge pull request #14 from eik-lib/rename
trygve-lie Mar 10, 2021
651f16b
chore(release): 1.0.0-next.2 [skip ci]
semantic-release-bot Mar 10, 2021
2cda882
chore: Clean up the package structure
Mar 11, 2021
6f9324f
Merge pull request #15 from eik-lib/pkg-strukture
trygve-lie Mar 11, 2021
b634537
fix: Add CommonJS support
Mar 11, 2021
fa72a18
chore: Lint love
Mar 11, 2021
56ac491
Merge pull request #16 from eik-lib/cjs
trygve-lie Mar 11, 2021
fc6630d
ci: Fix repo URL
Mar 11, 2021
58d296b
Merge pull request #17 from eik-lib/repo
trygve-lie Mar 11, 2021
1074bb5
chore(release): 1.0.0-next.3 [skip ci]
semantic-release-bot Mar 11, 2021
9e475c2
docs: Document module
Mar 14, 2021
4808835
chore: lint love
Mar 14, 2021
6960026
Merge pull request #18 from eik-lib/docs
trygve-lie Mar 14, 2021
bd07fe0
Update README.md
trygve-lie Mar 15, 2021
bc8a43a
Update README.md
trygve-lie Mar 15, 2021
d240a32
Update README.md
trygve-lie Mar 15, 2021
6564912
Update README.md
trygve-lie Mar 15, 2021
21680b0
Update README.md
trygve-lie Mar 15, 2021
d879553
Update README.md
trygve-lie Mar 15, 2021
a87bf89
Update README.md
trygve-lie Mar 15, 2021
78f02d2
Update README.md
trygve-lie Mar 15, 2021
7ac43b6
Update README.md
trygve-lie Mar 15, 2021
2f35956
Update README.md
trygve-lie Mar 15, 2021
aa073f6
Update README.md
trygve-lie Mar 15, 2021
f53f15d
feat: Make .file() return an object
Mar 17, 2021
9ea6800
chore: Lint love
Mar 17, 2021
d4138b3
test: Add tests and documentation
Mar 18, 2021
7aaac8c
doc: Fix example
Mar 18, 2021
dc6cd4e
Merge pull request #23 from eik-lib/return-obj
trygve-lie Mar 19, 2021
b37e787
chore(release): 1.0.0-next.4 [skip ci]
semantic-release-bot Mar 19, 2021
0505dcb
fix: Do not use getters and setters on public data object
Mar 23, 2021
0c55d59
Merge pull request #26 from eik-lib/no-get-set
trygve-lie Mar 23, 2021
f46ddcc
chore(release): 1.0.0-next.5 [skip ci]
semantic-release-bot Mar 23, 2021
1eb747d
doc: Fixed spelling error
Mar 27, 2021
a679f73
fix: Make default value of integrity to be undefined
Apr 9, 2021
582da7c
Merge pull request #28 from eik-lib/undefined-integrity
trygve-lie Apr 9, 2021
854fa1f
chore(release): 1.0.0-next.6 [skip ci]
semantic-release-bot Apr 9, 2021
6735ff2
chore: Use private properties
Oct 6, 2021
b179c85
test: run tests on node.js 16 instead of 15
Oct 6, 2021
9832b6e
chore: Add tests
Nov 2, 2021
dc48902
chore: lint love
Nov 2, 2021
19f0439
doc: Update documentation
Nov 2, 2021
cb2cd85
chore(deps): Updated dependencies
Nov 2, 2021
9e4ed46
Merge remote-tracking branch 'origin' into next
Aug 8, 2022
6d78ac6
chore(release): 2.0.0-next.1 [skip ci]
semantic-release-bot Aug 8, 2022
5de927c
feat: Use the new @eik/common-config-loader module (#104)
trygve-lie Aug 18, 2022
11fb244
chore(release): 2.0.0-next.2 [skip ci]
semantic-release-bot Aug 18, 2022
bbb20a5
Merge remote-tracking branch 'origin' into next
Aug 18, 2022
e94fefd
Merge branch 'next' of github.com:eik-lib/node-client into next
Aug 18, 2022
0fd760d
chore(release): 2.0.0-next.3 [skip ci]
semantic-release-bot Aug 18, 2022
d74f8c8
feat: Remove support for CJS. ESM only (#106)
trygve-lie Aug 22, 2022
cfd5178
chore(release): 2.0.0-next.4 [skip ci]
semantic-release-bot Aug 22, 2022
a557cfd
feat: add .mapping(dep) shorthand method to resolve mapped bare impor…
digitalsadhu Sep 20, 2022
c77f207
docs: add README.md documentation
digitalsadhu Sep 23, 2022
384bec6
Merge pull request #112 from eik-lib/add_mapping_method
digitalsadhu Sep 23, 2022
ce7a5ed
chore(release): 2.0.0-next.5 [skip ci]
semantic-release-bot Sep 23, 2022
89253e0
fix:add starting slash to file-urls (#114)
torbs Sep 30, 2022
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
6 changes: 2 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
push:
branches:
- master
- alpha
- beta
- next

jobs:
Expand All @@ -17,7 +15,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 16.x
- name: npm install
run: |
npm install
Expand All @@ -44,7 +42,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 16.x
- name: npm install
run: |
npm install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: [14.x, 16.x]
node-version: [16.x, 18.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
63 changes: 62 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,71 @@
## [1.1.29](https://github.com/eik-lib/node-client/compare/v1.1.28...v1.1.29) (2022-08-15)
# [2.0.0-next.5](https://github.com/eik-lib/node-client/compare/v2.0.0-next.4...v2.0.0-next.5) (2022-09-23)


### Features

* add .mapping(dep) shorthand method to resolve mapped bare imports directly ([a557cfd](https://github.com/eik-lib/node-client/commit/a557cfdc56f4553f721d1a67a7670eafc284b565))

# [2.0.0-next.4](https://github.com/eik-lib/node-client/compare/v2.0.0-next.3...v2.0.0-next.4) (2022-08-22)


### Features

* Remove support for CJS. ESM only ([#106](https://github.com/eik-lib/node-client/issues/106)) ([d74f8c8](https://github.com/eik-lib/node-client/commit/d74f8c8266b67119d8d110524533a0bd7ce19e7d))


### BREAKING CHANGES

* This PR removes the support for CJS in this module. This module is now ESM only.

* feat: Remove CJS support. ESM only.
* Support for CJS is now removed in this module. It is ESM only.

* ci: use 0.0.0.0 instead of localhost

* fix: remove console.log() statement

Co-authored-by: Trygve Lie <trygve.lie@finn.no>

# [2.0.0-next.3](https://github.com/eik-lib/node-client/compare/v2.0.0-next.2...v2.0.0-next.3) (2022-08-18)


### Bug Fixes

* **deps:** update dependency undici to v5.8.2 ([652c0af](https://github.com/eik-lib/node-client/commit/652c0af76d4eff970ba8954d8f287703c30acd73))

# [2.0.0-next.2](https://github.com/eik-lib/node-client/compare/v2.0.0-next.1...v2.0.0-next.2) (2022-08-18)


### Features

* Use the new @eik/common-config-loader module ([#104](https://github.com/eik-lib/node-client/issues/104)) ([5de927c](https://github.com/eik-lib/node-client/commit/5de927ca74c461be8d6bbd0048a2afc6812cb085))

# [2.0.0-next.1](https://github.com/eik-lib/node-client/compare/v1.1.28...v2.0.0-next.1) (2022-08-08)


### Bug Fixes

* Add CommonJS support ([b634537](https://github.com/eik-lib/node-client/commit/b6345378236d1bf60dc1ff6ceee1a285ca335e7f))
* Do not use getters and setters on public data object ([0505dcb](https://github.com/eik-lib/node-client/commit/0505dcb25b2563b826d5806fc30a7d148c111c00))
* Make default value of integrity to be undefined ([a679f73](https://github.com/eik-lib/node-client/commit/a679f733351413e5e59cbd0f71c86fef8a08042c))


### chore

* Rename module to @eik/node-client ([f3d8c73](https://github.com/eik-lib/node-client/commit/f3d8c7325b90b345a79df731544f53ebb11c81bf))


### Features

* Make .file() return an object ([f53f15d](https://github.com/eik-lib/node-client/commit/f53f15dae288fda4b4527a3b4c69bab2e56f5169))
* Rework module to suite current functionality of Eik ([559294c](https://github.com/eik-lib/node-client/commit/559294cc8d1bd793873ba02000da6376312e0160))


### BREAKING CHANGES

* Rename module to @eik/node-client
* API is reworked to suite the current functionality of Eik

## [1.1.28](https://github.com/eik-lib/node-client/compare/v1.1.27...v1.1.28) (2022-08-08)


Expand Down
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Set the module in development mode or not.

Whether import maps defined in the config should be loaded from the Eik server or not. The import maps is loaded by calling the `.load()` method and loaded the maps can be retrieved with the `.maps()` method. The import maps will be cached in the module.

## API
### options

This module has the following API

Expand Down Expand Up @@ -187,6 +187,37 @@ If `integrity` of the file is not available, the value for `integrity` will be `

Returns the import maps defined in Eik config from the Eik server. For the maps to be returned they need to be loaded from the Eik server. This is done by setting the `loadMaps` option on the constructor to `true`.

### .mapping(identifier)

Returns the last mapping entry for a given bare import `identifier`.
`identifier` is a `string` key from an import map and the returned `string` is a the matching value from the same import map entry.

#### arguments

| option | default | type | required | details |
| ---------- | ------- | -------- | -------- | ------------------- |
| identifier | | `string` | `true` | Bare import map key |

**Example:**

If an import map being used looks like:

```json
{
"imports": {
"react": "https://myserver.com/react/18.0.0/react.min.js"
}
}
```

When the mapping method is called:

```js
const absoluteURL = client.mapping('react');
```

`absoluteURL` will be `https://myserver.com/react/18.0.0/react.min.js`

## License

Copyright (c) 2021 FINN.no
Expand Down
16 changes: 4 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
{
"name": "@eik/node-client",
"version": "1.1.29",
"version": "2.0.0-next.5",
"description": "A node.js client for interacting with a Eik server.",
"type": "module",
"main": "./dist/index.cjs",
"exports": {
"import": "./src/index.js",
"require": "./dist/index.cjs"
},
"main": "./src/index.js",
"files": [
"CHANGELOG.md",
"package.json",
"LICENSE",
"dist",
"src"
],
"scripts": {
"test": "tap --no-coverage",
"lint:fix": "eslint --fix .",
"lint": "eslint .",
"prepare": "npm run -s build",
"build": "rollup -c"
"lint": "eslint ."
},
"repository": {
"type": "git",
Expand All @@ -37,7 +30,7 @@
},
"homepage": "https://github.com/eik-lib/node-client#readme",
"dependencies": {
"@eik/common": "3.0.1",
"@eik/common-config-loader": "4.0.0-next.8",
"abslog": "2.4.0",
"undici": "5.8.2"
},
Expand All @@ -50,7 +43,6 @@
"eslint-plugin-import": "2.26.0",
"eslint-plugin-prettier": "4.2.1",
"prettier": "2.7.1",
"rollup": "2.77.2",
"semantic-release": "19.0.3",
"tap": "16.3.0",
"@babel/eslint-parser": "7.18.9"
Expand Down
2 changes: 0 additions & 2 deletions release.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ module.exports = {
preset: 'angular',
branches: [
{ name: 'master' },
{ name: 'alpha', prerelease: true },
{ name: 'beta', prerelease: true },
{ name: 'next', prerelease: true },
],
};
16 changes: 0 additions & 16 deletions rollup.config.js

This file was deleted.

51 changes: 37 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { helpers } from '@eik/common';
/* eslint-disable no-restricted-syntax */
import { request } from 'undici';
import { join } from 'path';
import { join } from 'node:path';
import { URL } from 'node:url';
import loader from '@eik/common-config-loader';
import Asset from './asset.js';

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

const ABSOLUTE_URL_REGEX = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/;

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 +34,7 @@ const fetchImportMaps = async (urls = []) => {
`Unable to load import map file from server: ${err.message}`,
);
}
}
};

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

async load() {
this.#config = await helpers.getDefaults(this.#path);
this.#config = await loader.getDefaults(this.#path);
if (this.#loadMaps) {
this.#maps = await fetchImportMaps(this.#config.map);
}
Expand Down Expand Up @@ -83,7 +86,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 @@ -94,13 +98,32 @@ export default class NodeClient {

file(file = '') {
const base = this.base();
let value;
if (base && ABSOLUTE_URL_REGEX.test(base)) {
const baseURL = new URL(base);
const subPath = join(baseURL.pathname, file);
value = new URL(subPath, base).toString();
} else {
value = join(base, '/', file);
}

return new Asset({
value: `${base}${file}`,
value
});
}

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()',
);
}

mapping(dependency) {
let mapping = null;
for (const map of this.maps()) {
if (map?.imports[dependency]) mapping = map.imports[dependency];
}
return mapping;
}
}
Loading