Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
172 commits
Select commit Hold shift + click to select a range
951ad6c
chore: init
jmfrancois Feb 9, 2022
7e5903b
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Feb 9, 2022
7022f7e
feat: add assets-api package and start to use it
jmfrancois Feb 9, 2022
a77c39f
fix: inject version at build time
jmfrancois Feb 9, 2022
43804c1
chore: log error
jmfrancois Feb 9, 2022
42bd422
chore: simplify API
jmfrancois Feb 9, 2022
53e8c15
feat: use assets-api to get icons from pkg
jmfrancois Feb 9, 2022
64edb08
feat: add Code editor lazy load react-ace
jmfrancois Feb 9, 2022
6049a3a
feat: check if scripts exists
jmfrancois Feb 9, 2022
7cd06c5
chore: remove console.logs
jmfrancois Feb 10, 2022
838130b
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Feb 10, 2022
af78073
feat: add babel plugin to remove the need of version
jmfrancois Feb 10, 2022
3e19f32
chore: change getJSON api
jmfrancois Feb 11, 2022
15d9c31
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Feb 21, 2022
0a4fe8e
feat: add agrid use case
jmfrancois Feb 22, 2022
ed92fd9
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Feb 23, 2022
1c85f25
chore: upgrade
jmfrancois Feb 23, 2022
2f06926
Merge 1c85f25608d801870f7b45a2a9c57e3d55c31e57 into 1a20a28d55089dec9…
jmfrancois Feb 23, 2022
4690bda
feat: add react.lazy + suspense support
jmfrancois Feb 23, 2022
d4a5d08
Merge branch 'jmfrancois/feat/add-assets-api' of github.com:Talend/ui…
jmfrancois Feb 23, 2022
2aaa5f3
Merge d4a5d0804e5e03f58a49ceb9e340bac90c08cf90 into 1a20a28d55089dec9…
jmfrancois Feb 23, 2022
5b3f588
chore: remove import lazy everywhere
jmfrancois Feb 23, 2022
0773bbc
Merge branch 'jmfrancois/feat/add-assets-api' of github.com:Talend/ui…
jmfrancois Feb 23, 2022
e6101b7
Merge 0773bbcb520bab502611ed18dcdbfdf34e5e12cc into 1a20a28d55089dec9…
jmfrancois Feb 23, 2022
fb5e77d
fix(playground): remove integrity on local to support refresh
jmfrancois Feb 24, 2022
854cfbd
chore: refactor APIs
jmfrancois Feb 24, 2022
dc3ad06
chore: prepare babel plugin to handle getUMD injection
jmfrancois Feb 24, 2022
cb60a46
Merge branch 'jmfrancois/feat/add-assets-api' of github.com:Talend/ui…
jmfrancois Feb 24, 2022
b357c9c
Merge cb60a46cb0e60d5e1b31f11adc848f544e30773b into 63079b40d30facd46…
jmfrancois Feb 24, 2022
95dee6d
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Feb 25, 2022
b72975d
fix: cache found
jmfrancois Feb 25, 2022
5ad8e11
fix: cache found
jmfrancois Feb 25, 2022
75d2546
feat: make locales taken from our cdn
jmfrancois Feb 25, 2022
0ef170b
Merge 75d25469f34473c21e85e8c70726172e544d679b into a0bb030ee0fd29363…
jmfrancois Feb 25, 2022
e630f70
feat: break if no talend
jmfrancois Feb 28, 2022
12ae362
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Feb 28, 2022
96244b6
Merge 12ae362d35c5d2bc6ffcd1c8db3c680dfe8813a7 into 7946db15e7f69b07d…
jmfrancois Feb 28, 2022
c77d94a
fix: topology
jmfrancois Feb 28, 2022
658fb55
fix: assets api getJSON arguments
jmfrancois Feb 28, 2022
1a27e0e
Merge branch 'jmfrancois/feat/add-assets-api' of github.com:Talend/ui…
jmfrancois Feb 28, 2022
ad85545
Merge 1a27e0e0b4d3c0282ea116b03f2246ca0692cdf5 into 7946db15e7f69b07d…
jmfrancois Feb 28, 2022
dd5a536
fix: geochart
jmfrancois Feb 28, 2022
3191d86
Merge branch 'jmfrancois/feat/add-assets-api' of github.com:Talend/ui…
jmfrancois Feb 28, 2022
c4170cd
Merge 3191d86265f7415e86d58d264c004717a0e41eb8 into 7946db15e7f69b07d…
jmfrancois Feb 28, 2022
609754d
chore: remove test:demo from assets-api
jmfrancois Feb 28, 2022
333c45e
Merge 609754df83daf8ff03d84470340bb91321133e73 into 7946db15e7f69b07d…
jmfrancois Feb 28, 2022
7b65e86
fix: make it work
jmfrancois Feb 28, 2022
421a123
Merge branch 'jmfrancois/feat/add-assets-api' of github.com:Talend/ui…
jmfrancois Feb 28, 2022
2b94ced
Merge 421a123503125b55573fd879d48a727e3441378d into a0ea246b2456e383b…
jmfrancois Feb 28, 2022
bd3264f
chore: add tmp babelrc config
jmfrancois Mar 1, 2022
e13a1f4
Merge branch 'jmfrancois/feat/add-assets-api' of github.com:Talend/ui…
jmfrancois Mar 1, 2022
ce20b55
Merge e13a1f4114e99a5e9e562893e72e4e2c224b358f into a0ea246b2456e383b…
jmfrancois Mar 1, 2022
7c0f2f7
feat: add Error if varName not found after TIMEOUT (10s)
jmfrancois Mar 1, 2022
489b959
Merge branch 'jmfrancois/feat/add-assets-api' of github.com:Talend/ui…
jmfrancois Mar 1, 2022
4944d86
Merge 489b959803f99237371a0766eb914ac55e67a158 into a0ea246b2456e383b…
jmfrancois Mar 1, 2022
bd955db
chore: upgrade and implement builtVersion algo
jmfrancois Mar 2, 2022
5075db0
feat: add support for project version
jmfrancois Mar 2, 2022
4a3a86d
feat: add support for optional name
jmfrancois Mar 2, 2022
732ace5
Merge branch 'jmfrancois/feat/add-assets-api' of github.com:Talend/ui…
jmfrancois Mar 2, 2022
578ef21
Merge 732ace54f2de71f962562d39771190cfa376637e into e5390d0d5dd99d606…
jmfrancois Mar 2, 2022
ceb4f4d
fix: support base
jmfrancois Mar 2, 2022
5a8d8f2
Merge branch 'jmfrancois/feat/add-assets-api' of github.com:Talend/ui…
jmfrancois Mar 2, 2022
ae1f754
Merge 5a8d8f227d6ba67e8c1c161b831092ba5aa4e7d4 into e5390d0d5dd99d606…
jmfrancois Mar 2, 2022
4dee206
feat: add getUMD transpile from resolver
jmfrancois Mar 2, 2022
965c5d5
feat: add getUMD transpile from resolver
jmfrancois Mar 2, 2022
6498986
chore: cleanup
jmfrancois Mar 3, 2022
0585939
Merge branch 'jmfrancois/feat/add-assets-api' of github.com:Talend/ui…
jmfrancois Mar 3, 2022
6912efb
chore: remove versions and path + setup babel plugin
jmfrancois Mar 3, 2022
6bbec14
Merge 6912efbbed64f0d0b51ac9c6d6cfb60ee3c83d18 into e5390d0d5dd99d606…
jmfrancois Mar 3, 2022
5268584
chore: remove babel plugin
jmfrancois Mar 3, 2022
54df8e6
Merge branch 'jmfrancois/feat/add-assets-api' of github.com:Talend/ui…
jmfrancois Mar 3, 2022
b8921cd
Merge 54df8e67b0fd4cd3d47c553918860c3c60a009e2 into d839ab8edab1cc564…
jmfrancois Mar 3, 2022
48716ea
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Mar 4, 2022
9603827
Merge 48716ea4e6b7558209f6e6e89a1a5dee5e8320a3 into 2cd33bb999d35d0a9…
jmfrancois Mar 4, 2022
e50f1b7
chore: apply prettier on modified files
github-actions[bot] Mar 4, 2022
f3d1504
chore: cleanup
jmfrancois Mar 4, 2022
bffeabf
chore: upgrade
jmfrancois Mar 4, 2022
2f54c2e
chore: upgrade and cleanup
jmfrancois Mar 4, 2022
6c72be6
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Mar 4, 2022
496c983
chore: suspense
jmfrancois Mar 4, 2022
c094532
test: refactor test using rtl
jmfrancois Mar 7, 2022
ac12fcd
test: deprecated form widget
jmfrancois Mar 7, 2022
ff17618
test: fix datagrid
jmfrancois Mar 7, 2022
331acbd
chore: remove --silent on test
jmfrancois Mar 8, 2022
25afd56
test: add some
jmfrancois Mar 8, 2022
ec8f355
test(dataviz): fix
jmfrancois Mar 9, 2022
28c6d4f
fix: fix esmodule def
jmfrancois Mar 9, 2022
029f86a
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Mar 9, 2022
9e25b37
test: fix read pkg up
jmfrancois Mar 9, 2022
f432805
chore: remove babelrc from datagrid storybook
jmfrancois Mar 10, 2022
0d8f1a3
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Mar 10, 2022
1b529b8
feat: add toDefaultModule
jmfrancois Mar 10, 2022
fb3b0f2
Merge 1b529b8b943f557c70960aa8abcd93924ce4d5c1 into b412cec71c8eeda37…
jmfrancois Mar 10, 2022
2a8c931
chore: yarn-deduplicate
github-actions[bot] Mar 10, 2022
2b220eb
fix: test
jmfrancois Mar 11, 2022
0fddf7d
Merge branch 'jmfrancois/feat/add-assets-api' of github.com:Talend/ui…
jmfrancois Mar 11, 2022
3df8f0d
chore: downgrade read-pkg-up to support node14
jmfrancois Mar 11, 2022
672bf34
test: fix react ace
jmfrancois Mar 11, 2022
7e0d83e
test: fix forms
jmfrancois Mar 11, 2022
c92979f
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Mar 11, 2022
6aa87cc
Merge c92979f0f9da2707ce625ef65507eb4cb1219356 into eb0717b9f305eefe9…
jmfrancois Mar 11, 2022
099caa5
chore: yarn-deduplicate
github-actions[bot] Mar 11, 2022
927ad9d
chore: remove babelrc from storybook folder
jmfrancois Mar 11, 2022
e60244e
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Mar 11, 2022
0d44297
chore: revert change in design-tokens
jmfrancois Mar 11, 2022
99e6e8f
chore: align deps
jmfrancois Mar 11, 2022
3b4ac4a
doc: add some
jmfrancois Mar 11, 2022
332cfcd
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Mar 11, 2022
a9037bc
chore: add doc + use toDefaultModule
jmfrancois Mar 18, 2022
6c970a2
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Mar 18, 2022
514982f
Update packages/assets-api/README.md
jmfrancois Mar 18, 2022
0ae09f3
Update packages/assets-api/src/index.ts
jmfrancois Mar 18, 2022
9ea303f
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Mar 23, 2022
6f7b29c
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Mar 23, 2022
2558f84
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Apr 19, 2022
38ad87e
fix: typings
jmfrancois Apr 19, 2022
ead22ac
chore: add more timeout
jmfrancois Apr 19, 2022
d76933f
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Apr 20, 2022
d76665f
chore: update CI to build assets-api for DS
jmfrancois Apr 20, 2022
9fef15c
chore: drop cypress form install
jmfrancois Apr 20, 2022
d30cbce
chore: update ts config
jmfrancois Apr 20, 2022
f2a47cd
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Apr 22, 2022
3746d84
doc: update
jmfrancois Apr 22, 2022
41c155e
Merge 3746d84a482ade135850e0bcebde949fb79f9216 into 2875eb2ce5ab0b1f9…
jmfrancois Apr 22, 2022
1d9b322
chore: yarn-deduplicate
github-actions[bot] Apr 22, 2022
24bb10d
chore: try to ignore spec file
jmfrancois Apr 22, 2022
a2e3dd8
Merge branch 'jmfrancois/feat/add-assets-api' of github.com:Talend/ui…
jmfrancois Apr 22, 2022
f023dee
chore: up
jmfrancois Apr 22, 2022
477802d
Update packages/assets-api/README.md
jmfrancois Apr 22, 2022
908208f
Update packages/assets-api/README.md
jmfrancois Apr 22, 2022
3d014f0
Update packages/assets-api/README.md
jmfrancois Apr 22, 2022
2042b87
Update packages/assets-api/README.md
jmfrancois Apr 22, 2022
c48ade9
Update packages/assets-api/README.md
jmfrancois Apr 22, 2022
a70041a
Update packages/assets-api/README.md
jmfrancois Apr 22, 2022
8eb0969
Update packages/assets-api/README.md
jmfrancois Apr 22, 2022
0440ad4
Update packages/assets-api/README.md
jmfrancois Apr 22, 2022
01992ce
Update packages/assets-api/README.md
jmfrancois Apr 22, 2022
4b72f53
Update packages/assets-api/README.md
jmfrancois Apr 22, 2022
a26c39b
Update packages/assets-api/README.md
jmfrancois Apr 22, 2022
5a35295
Update packages/assets-api/README.md
jmfrancois Apr 22, 2022
610c4e0
Update packages/assets-api/README.md
jmfrancois Apr 22, 2022
51547e4
Update packages/assets-api/README.md
jmfrancois Apr 22, 2022
45ef1ab
Update packages/assets-api/README.md
jmfrancois Apr 22, 2022
a305133
Update packages/assets-api/src/index.ts
jmfrancois Apr 22, 2022
5097e3e
Update packages/assets-api/src/index.ts
jmfrancois Apr 22, 2022
f70ae3a
Update packages/assets-api/src/index.ts
jmfrancois Apr 22, 2022
1aa9d06
Update packages/assets-api/src/index.ts
jmfrancois Apr 22, 2022
708b3c2
Update packages/components/package.json
jmfrancois Apr 22, 2022
dc348c5
doc: update
jmfrancois Apr 22, 2022
c6b94c0
chore: make test more clear
jmfrancois Apr 22, 2022
aa7b44f
chore: revert ds changes
jmfrancois Apr 22, 2022
a977d43
Merge aa7b44ff869efa2a09dbef273f9f428f0ac11f12 into ce7950623d8e4b2b4…
jmfrancois Apr 22, 2022
d5ed3b4
chore: yarn-deduplicate
github-actions[bot] Apr 22, 2022
b25eb57
chore: up
jmfrancois Apr 25, 2022
7a2e7a7
fix(dynamic cdn): handle package without varName
jmfrancois Apr 25, 2022
14968ea
Update packages/datagrid/src/components/DataGrid/DataGrid.component.js
jmfrancois Apr 28, 2022
cd989dc
Update packages/forms/src/UIForm/fields/Code/Code.component.test.js
jmfrancois Apr 28, 2022
54664bc
chore: remove babelrc
jmfrancois Apr 28, 2022
6d8fadc
test: remove timeout
jmfrancois Apr 28, 2022
170fc47
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois Apr 28, 2022
0546e93
chore: revert ds action cache
jmfrancois Apr 28, 2022
e99cda2
chore: align deps
jmfrancois Apr 28, 2022
d9dfa77
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois May 2, 2022
9d42821
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois May 2, 2022
7b37d45
Update packages/assets-api/README.md
jmfrancois May 3, 2022
35cccea
Update packages/assets-api/README.md
jmfrancois May 3, 2022
2adb4c9
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois May 3, 2022
837a4a7
chore: cleanup
jmfrancois May 3, 2022
bdf31f3
chore: add changeset
jmfrancois May 3, 2022
9136236
chore: add changeset
jmfrancois May 3, 2022
27f7d93
feat: go back to minor
jmfrancois May 3, 2022
92a2425
Merge branch 'master' into jmfrancois/feat/add-assets-api
jmfrancois May 3, 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
5 changes: 5 additions & 0 deletions .changeset/early-files-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@talend/react-datagrid': minor
---

feat: use @talend/assets-api to load datagrid umds on demand
5 changes: 5 additions & 0 deletions .changeset/fifty-camels-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@talend/scripts-config-react-webpack': minor
---

feat: add CDN_URL to /cdn by default
6 changes: 6 additions & 0 deletions .changeset/rich-swans-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@talend/design-system': minor
---

feat: use @talend/assets-api to load icons

5 changes: 5 additions & 0 deletions .changeset/thirty-terms-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@talend/react-forms': minor
---

Use @talend/assets-api to load aceeditor
5 changes: 5 additions & 0 deletions .changeset/tiny-carrots-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@talend/react-dataviz': minor
---

feat: Use @talend/assets-api to load topologies.
1 change: 1 addition & 0 deletions .github/workflows/design-system-component-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:

- name: Build @talend/design-tokens
run: |
yarn workspace @talend/assets-api run build:lib
yarn workspace @talend/design-tokens run build:lib

- name: Cypress Component Testing
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/design-system-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:

- name: Build Storybook of the design tokens
run: |
yarn workspace @talend/assets-api run build:lib
yarn workspace @talend/design-tokens run build:lib
yarn workspace @talend/design-tokens run build-storybook

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/visual-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
- name: Build @talend/design-tokens
if: matrix.package == 'design-system'
run: |
yarn workspace @talend/assets-api run build:lib
yarn workspace @talend/design-tokens run build:lib

- name: Build @talend/*
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
build
dist
node_modules
__fixtures__
74 changes: 74 additions & 0 deletions packages/assets-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# @talend/assets-api

Copy link
Contributor

@Benrajalu Benrajalu Mar 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This maybe requires more context than the requirements.

What real-life issues is it trying to solve? Can you give examples? Is it replacing something? As a newbie I don't really understand the point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with that, and it's missing a description on top to tell what it does. The documentation starts with requirements but we don't know requirements for what.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me know if this is better now

Assets are files from a npm package which can be needed at some point by a web application. It can be a stylesheet, a SVG icon, a js script, a json file, etc...

At Talend our web applications may rely on a CDN to load libraries like lodash, d3 but also @talend/design-system using UMD distribution format. An application rely on a CDN depending of the execution context; We are following 12 factors principals. So the same code base must work in both case so an asset url may change from `/cdn/my-package/1.2.3/dist/my-assets.svg` to `https://mycdn.talend.com/my-package/1.2.3/dist/my-assets.svg`.

This is made possible using custom configuration of `@talend/dynamic-cdn-webpack-plugin`. Now we also need to be able to load translations, icons and more **assets** from the code.

This package exposes a simple and friendly API to let developers access assets without the complexity of computing URL depending on the context (CDN or not).

## Learn with examples

First you need to ensure you have setup the [babel plugin](https://npmjs.com/package/@talend/babel-plugin-assets-api) or you use @talend/scripts-core to build your lib / project.

Then we can start with this global example:

```javascript
import assetsAPI from '@talend/assets-api';

// The lowest level API is the ability to get the URL of anything. Here, a CSS file.
const href = assetsApi.getURL('/dist/styles/ag-grid.css', 'ag-grid-community');
// babel will add all missing arguments and at runtime you will have
console.log(href);
// -> 'https://unpkg.com/ag-grid-community@25.0.0/dist/styles/ag-grid.css';

// Higher level APIs enable users to get a JSON file for locales, timezones, etc...
async function getTopology(file) {
const locales = await assetsAPI.getJSON(
`/dist/assets/maps/${file}.topo.json`,
);
}


// We can also lazy load a component from a UMD.
// This one is a bit more complex. You have to know that React.lazy wants a default esModule from a Promise. This is what getUMD + toDefaultModule give you.
const AgGridReact = React.lazy(() =>
assetsApi
.getUMD('ag-grid-community')
.then(() => assetsApi.getUMD('ag-grid-react'))
.then(mod => assetsApi.toDefaultModule(mod.AgGridReact))
);


// Finally, this is how we load styles from a lazy loaded component.
export default function DataGrid(props) {
//...
useEffect(() => {
const href = assetsApi.getURL('/dist/styles/ag-grid.css', 'ag-grid-community');
assetsApi.addStyle({ href });
}, []);
//...
return <React.Suspense fallback={}>AgGridReact</React.Suspense>
}
```

## Requirements

- devs do not have to write the version: it is injected at build time thanks to [babel plugin](https://npmjs.com/package/@talend/babel-plugin-assets-api)
- the assets' version is implicitly specified by the consumer webapp (`talend-scripts` adds global data that is then read by the API at runtime)
- the inject.js script will be able to control this version (it should update meta value)
- `sessionStorage` is used to let anyone override a version locally
- the API is compatible with `React.Suspense` / lazy React APIs
- for UMDs, the path is computed form `module-to-cdn` and injected at build time thanks to the babel plugin
- for relative paths in a package, the name of the package is optional

## How to configure the CDN to use ?

The assets API uses a global function to compute the URL: `window.Talend.getCDNUrl()`. By default the package will add it for you. This version will use a global `CDN_URL` with the following shape:

```javascript
`${CDN_URL}/${info.name}/${info.version}${info.path}`;
```

but fallbacks to unpkg.com public CDN if no CDN_URL is provided.
41 changes: 41 additions & 0 deletions packages/assets-api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@talend/assets-api",
"description": "A set of API designed to access assets using CDN",
"types": "lib/index.d.ts",
"main": "lib/index.js",
"mainSrc": "src/index.ts",
"license": "Apache-2.0",
"scripts": {
"pre-release": "echo no pre-release for assets-api",
"build:lib": "talend-scripts build:ts:lib",
"start": "echo nothing to start",
"test": "talend-scripts test",
"test:watch": "talend-scripts test --watch",
"test:cov": "talend-scripts test --coverage",
"test:demo": "echo nothing to demo",
"lint:es": "talend-scripts lint:es --format json -o eslint-report.json",
"lint": "talend-scripts lint:es --format json -o eslint-report.json"
},
"keywords": [
"talend"
],
"author": "Talend Frontend <frontend@talend.com>",
"homepage": "https://github.com/Talend/ui/tree/master/packages/assets-api#readme",
"bugs": {
"url": "https://github.com/Talend/ui/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/Talend/ui.git"
},
"dependencies": {},
"devDependencies": {
"@talend/scripts-core": "^11.6.0",
"@talend/scripts-preset-react-lib": "^11.0.2",
"read-pkg-up": "^7.0.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite the downgrade

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have read-pkg-up in multiple scripts in CJS and I prefere be aligned.
This could be ok here but not in other scripts.
sindresorhus/read-package-up#20

It could be upgraded if we move to ESM every where.

},
"publishConfig": {
"access": "public"
},
"version": "1.0.0"
}
33 changes: 33 additions & 0 deletions packages/assets-api/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import readPackageUp from 'read-pkg-up';
import assetsApi, { Asset } from '.';

const iconsInfo = readPackageUp.sync({ cwd: require.resolve('@talend/icons') });
const currentInfo = readPackageUp.sync({ cwd: __dirname });

describe('assets-api', () => {
describe('getURL', () => {
it('should return unpkg url', () => {
const assetsPath = '/dist/svg-bundles/all.svg';
const url = assetsApi.getURL(assetsPath, '@talend/icons', iconsInfo?.packageJson.version);
expect(url).toBe(
`https://unpkg.com/@talend/icons@${iconsInfo?.packageJson.version}${assetsPath}`,
);
});
it('should use global getCDNUrl', () => {
const assetsPath = '/package.json';
const original = window.Talend.getCDNUrl;
window.Talend.getCDNUrl = jest.fn(
(info: Asset) => `https://mycdn.talend.com/${info.name}/${info.version}${info.path}`,
);
const url = assetsApi.getURL(
assetsPath,
'@talend/assets-api',
currentInfo?.packageJson.version,
);
expect(url).toBe(
`https://mycdn.talend.com/@talend/assets-api/${currentInfo?.packageJson.version}${assetsPath}`,
);
window.Talend.getCDNUrl = original;
});
});
});
Loading