Compare commits

...

104 Commits

Author SHA1 Message Date
semantic-release-bot 821efd74fd chore(release): 4.1.0-develop.5 [skip ci]
# [4.1.0-develop.5](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.1.0-develop.4...v4.1.0-develop.5) (2023-07-02)
2023-07-02 21:16:08 +00:00
Derrick Hammer f41cdbaa01
Merge remote-tracking branch 'origin/develop' into develop 2023-07-02 17:15:17 -04:00
Derrick Hammer c26c34ac19
dep: rollup needs to be a main dep 2023-07-02 17:15:13 -04:00
semantic-release-bot bf99834981 chore(release): 4.1.0-develop.4 [skip ci]
# [4.1.0-develop.4](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.1.0-develop.3...v4.1.0-develop.4) (2023-07-02)
2023-07-02 21:09:32 +00:00
Derrick Hammer 8f5ebf53a0
Merge remote-tracking branch 'origin/develop' into develop 2023-07-02 17:08:33 -04:00
Derrick Hammer 796391a8f0
dep: update/re-order deps and add plugin-wasm 2023-07-02 17:08:28 -04:00
semantic-release-bot 13b362781a chore(release): 4.1.0-develop.3 [skip ci]
# [4.1.0-develop.3](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.1.0-develop.2...v4.1.0-develop.3) (2023-07-02)

### Bug Fixes

* add inlineDynamicImports ([3e4d300](3e4d3007b6))
2023-07-02 15:45:57 +00:00
Derrick Hammer 27cfcacc71
Merge remote-tracking branch 'origin/develop' into develop 2023-07-02 11:45:10 -04:00
Derrick Hammer 3e4d3007b6
fix: add inlineDynamicImports 2023-07-02 11:45:05 -04:00
semantic-release-bot b12a82826e chore(release): 4.1.0-develop.2 [skip ci]
# [4.1.0-develop.2](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.1.0-develop.1...v4.1.0-develop.2) (2023-07-02)

### Bug Fixes

* use optional chain syntax as the property might not be set ([2077d4e](2077d4e70d))
2023-07-02 15:35:41 +00:00
Derrick Hammer b50e9b4428
Merge remote-tracking branch 'origin/develop' into develop 2023-07-02 11:34:48 -04:00
Derrick Hammer 2077d4e70d
fix: use optional chain syntax as the property might not be set 2023-07-02 11:34:41 -04:00
semantic-release-bot 5835d7cf66 chore(release): 4.1.0-develop.1 [skip ci]
# [4.1.0-develop.1](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.12...v4.1.0-develop.1) (2023-07-02)

### Bug Fixes

* inject browser options into node-resolve plugin if config.browser is true ([70a531e](70a531e5aa))

### Features

* add plugin-wasm ([57ef73d](57ef73d9dc))
2023-07-02 08:01:16 +00:00
Derrick Hammer 30554e2dfe
Merge remote-tracking branch 'origin/develop' into develop 2023-07-02 04:00:12 -04:00
Derrick Hammer 57ef73d9dc
feat: add plugin-wasm 2023-07-02 03:59:58 -04:00
Derrick Hammer 70a531e5aa
fix: inject browser options into node-resolve plugin if config.browser is true 2023-07-02 03:59:42 -04:00
semantic-release-bot 8189deb964 chore(release): 4.0.2-develop.12 [skip ci]
## [4.0.2-develop.12](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.11...v4.0.2-develop.12) (2023-07-02)

### Bug Fixes

* need to split ts moduleResolution to the tsconfig file ([d31720c](d31720ce14))
2023-07-02 04:47:18 +00:00
Derrick Hammer 76a0bca0d5
Merge remote-tracking branch 'origin/develop' into develop 2023-07-02 00:46:25 -04:00
Derrick Hammer d31720ce14
fix: need to split ts moduleResolution to the tsconfig file 2023-07-02 00:46:20 -04:00
semantic-release-bot 33ad206a95 chore(release): 4.0.2-develop.11 [skip ci]
## [4.0.2-develop.11](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.10...v4.0.2-develop.11) (2023-07-02)

### Bug Fixes

* set TS moduleResolution to nodenext ([f1b82f8](f1b82f85b1))
2023-07-02 04:41:40 +00:00
Derrick Hammer 94f7ada8b3
Merge remote-tracking branch 'origin/develop' into develop 2023-07-02 00:40:40 -04:00
Derrick Hammer f1b82f85b1
fix: set TS moduleResolution to nodenext 2023-07-02 00:40:34 -04:00
semantic-release-bot 081ab4fd87 chore(release): 4.0.2-develop.10 [skip ci]
## [4.0.2-develop.10](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.9...v4.0.2-develop.10) (2023-07-02)

### Bug Fixes

* needs to extend presetter-preset-strict ([d526d8a](d526d8ad6c))
2023-07-02 04:23:14 +00:00
Derrick Hammer d526d8ad6c
fix: needs to extend presetter-preset-strict 2023-07-02 00:22:06 -04:00
semantic-release-bot 7507d8e5ef chore(release): 4.0.2-develop.9 [skip ci]
## [4.0.2-develop.9](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.8...v4.0.2-develop.9) (2023-06-30)

### Bug Fixes

* outDir should not be an array and needs to be under compilerOptions ([f392036](f3920365cc))
2023-06-30 08:36:46 +00:00
Derrick Hammer 89d950dc9c
Merge remote-tracking branch 'origin/develop' into develop 2023-06-30 04:35:44 -04:00
Derrick Hammer f3920365cc
fix: outDir should not be an array and needs to be under compilerOptions 2023-06-30 04:35:37 -04:00
semantic-release-bot 1e1f0508bc chore(release): 4.0.2-develop.8 [skip ci]
## [4.0.2-develop.8](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.7...v4.0.2-develop.8) (2023-06-30)

### Bug Fixes

* buildSource needs to be src ([f1d13d0](f1d13d00f1))
2023-06-30 08:15:29 +00:00
Derrick Hammer ad8915911d
Merge remote-tracking branch 'origin/develop' into develop 2023-06-30 04:14:39 -04:00
Derrick Hammer e0b241a76a
refactor: add clean:buildOutput script 2023-06-30 04:14:34 -04:00
Derrick Hammer f1d13d00f1
fix: buildSource needs to be src 2023-06-30 04:12:23 -04:00
semantic-release-bot 086231df05 chore(release): 4.0.2-develop.7 [skip ci]
## [4.0.2-develop.7](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.6...v4.0.2-develop.7) (2023-06-30)

### Bug Fixes

* typescript needs to come before rollup ([6be363c](6be363c7c0))
2023-06-30 07:56:18 +00:00
Derrick Hammer de6d64f84b
Merge remote-tracking branch 'origin/develop' into develop 2023-06-30 03:55:23 -04:00
Derrick Hammer 6be363c7c0
fix: typescript needs to come before rollup 2023-06-30 03:55:18 -04:00
semantic-release-bot 12e4e58128 chore(release): 4.0.2-develop.6 [skip ci]
## [4.0.2-develop.6](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.5...v4.0.2-develop.6) (2023-06-30)

### Bug Fixes

* add build:typescript:* to build script ([edf1960](edf1960010))
2023-06-30 07:46:26 +00:00
Derrick Hammer 7059f28149
Merge remote-tracking branch 'origin/develop' into develop 2023-06-30 03:45:38 -04:00
Derrick Hammer ab3c7bada2
refactor: change source to build, and add new buildSource var. Add tsconfig.build overrides 2023-06-30 03:45:26 -04:00
Derrick Hammer edf1960010
fix: add build:typescript:* to build script 2023-06-30 03:38:40 -04:00
semantic-release-bot 17d7e7b4c2 chore(release): 4.0.2-develop.5 [skip ci]
## [4.0.2-develop.5](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.4...v4.0.2-develop.5) (2023-06-30)

### Bug Fixes

* dont pass file as argument ([41645d9](41645d9661))
2023-06-30 07:23:19 +00:00
Derrick Hammer 23d0614a02
Merge remote-tracking branch 'origin/develop' into develop 2023-06-30 03:22:19 -04:00
Derrick Hammer 41645d9661
fix: dont pass file as argument 2023-06-30 03:22:13 -04:00
semantic-release-bot b2c075e0d0 chore(release): 4.0.2-develop.4 [skip ci]
## [4.0.2-develop.4](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.3...v4.0.2-develop.4) (2023-06-30)

### Bug Fixes

* update tsconfig.config ([a9001da](a9001da273))
2023-06-30 07:18:23 +00:00
Derrick Hammer bb727ae72a
Merge remote-tracking branch 'origin/develop' into develop 2023-06-30 03:17:26 -04:00
Derrick Hammer a9001da273
fix: update tsconfig.config 2023-06-30 03:17:18 -04:00
semantic-release-bot 4afc8e4f8a chore(release): 4.0.2-develop.3 [skip ci]
## [4.0.2-develop.3](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.2...v4.0.2-develop.3) (2023-06-30)

### Bug Fixes

* add [@ts-nocheck](https://git.lumeweb.com/ts-nocheck) for rollup config ([cc72325](cc72325e5f))
2023-06-30 06:55:47 +00:00
Derrick Hammer 6b2791f842
Merge remote-tracking branch 'origin/develop' into develop 2023-06-30 02:54:45 -04:00
Derrick Hammer cc72325e5f
fix: add @ts-nocheck for rollup config 2023-06-30 02:54:37 -04:00
semantic-release-bot 6c5fa4a0aa chore(release): 4.0.2-develop.2 [skip ci]
## [4.0.2-develop.2](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.1...v4.0.2-develop.2) (2023-06-30)

### Bug Fixes

* add files to package.json ([486314d](486314de6b))
2023-06-30 06:05:06 +00:00
Derrick Hammer c5210eec0b
Merge remote-tracking branch 'origin/develop' into develop 2023-06-30 02:04:20 -04:00
Derrick Hammer 486314de6b
fix: add files to package.json 2023-06-30 02:04:13 -04:00
semantic-release-bot f61bb3b829 chore(release): 4.0.2-develop.1 [skip ci]
## [4.0.2-develop.1](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.1...v4.0.2-develop.1) (2023-06-30)
2023-06-30 05:53:33 +00:00
Derrick Hammer 9f090fb1a9
ci: update package name 2023-06-30 01:51:31 -04:00
Derrick Hammer d5e6ab23ae
ci: add @semantic-release/git 2023-06-30 01:34:33 -04:00
Derrick Hammer 653edbe8ce
ci: add @semantic-release/changelog 2023-06-30 01:29:47 -04:00
Derrick Hammer 6b364180f0
ci: add .releaserc.json 2023-06-30 01:27:50 -04:00
Derrick Hammer f91e2d356f
ci: add semantic-release 2023-06-30 01:25:32 -04:00
Derrick Hammer 12dbad4a51
ci: add semantic-release script 2023-06-30 01:23:09 -04:00
Derrick Hammer a6c1b7eacb
ci: update package.json scripts 2023-06-30 01:21:20 -04:00
Derrick Hammer 3ee5097728
ci: update package.json 2023-06-30 01:18:47 -04:00
Derrick Hammer 0950557182
ci: add ci config 2023-06-30 01:16:34 -04:00
Derrick Hammer 33f9ed88be
refactor: remove esm rollup output 2023-06-30 01:13:12 -04:00
Derrick Hammer 729c37ef18
refactor: move json plugin to be 1st 2023-06-30 01:12:46 -04:00
Derrick Hammer 0d2816fb8e
refactor: do not use a TS rollup plugin, but instead call tsc directly first 2023-06-30 01:11:55 -04:00
Derrick Hammer 2e05208469
Merge branch 'split' 2023-06-30 00:33:28 -04:00
Alvis HT Tang a62e640bd9 chore(release): publish v4.0.1 2023-06-21 16:24:36 +01:00
Alvis HT Tang 547dbc4a85 chore(release): publish v4.0.0 2023-06-19 15:59:45 +01:00
Alvis HT Tang 2e8a53c7a9 fix(preset-rollup): make the rollup preset compatible with ESM 2023-06-17 15:20:03 +01:00
Alvis HT Tang bbd74055a1 fix: update outdated packages 2023-06-15 10:50:26 +01:00
Alvis HT Tang 4e671b7289 refactor(preset-rollup): normalize config in functional way 2023-06-13 10:50:26 +01:00
Alvis HT Tang 2a87e456b0 chore: use pnpm for workspace management 2023-06-10 10:50:25 +01:00
Alvis HT Tang bc498596b8 feat: convert the whole project into ESM
BREAKING CHANGE:
- by default, client project emit ESM and for clarity preset-essentials has been renamed to preset-esm
- ts-node is removed in favor of a more powerful and less buggy tsx
2023-06-08 10:50:25 +01:00
Alvis HT Tang 5bb53481b0 feat(types): separate types from presetter 2023-06-05 13:55:42 +01:00
Alvis HT Tang ae48726a6c chore: allow tests can be done individually 2023-06-03 08:39:01 +01:00
Alvis HT Tang 138002cd51 fix(preset-rollup): inject NODE_ENV for build and develop stages 2023-05-21 22:23:48 +08:00
Alvis HT Tang 57578e9398 style: make any node build-in modules explicitly imported first 2023-05-21 10:47:56 +08:00
Alvis HT Tang 2e5652d84b chore(release): publish v3.5.5 2023-03-31 22:41:18 +01:00
Alvis HT Tang f7f9f0ac7b chore(release): publish v3.5.4 2023-03-30 15:54:09 +01:00
Alvis HT Tang 360aa8f073 chore(release): publish v3.5.3 2023-03-26 13:30:47 +01:00
Alvis HT Tang 26fa4da069 chore(release): publish v3.5.2 2023-03-26 08:46:08 +01:00
Alvis Tang d2cc99fae3 chore(release): publish v3.5.1 2023-03-18 12:59:51 +00:00
Alvis HT Tang 0db2a739f0 chore(release): publish v3.5.0 2022-09-23 18:50:30 +01:00
Alvis HT Tang 57710e7474 build: move .presetterrc to the root 2022-09-23 14:18:27 +01:00
Alvis HT Tang 21f28a21d2 refactor(rollup): remove unnecessary async waits 2022-09-23 13:50:33 +01:00
Alvis HT Tang 93a1ed2b0d refactor(presetter): remove dependency on fs-extra 2022-09-23 13:18:11 +01:00
Alvis HT Tang aae318098d chore(release): publish v3.4.1 2022-08-10 14:07:13 +01:00
Alvis HT Tang cf8be54e88 fix(presetter): merge arrays only if the values are all primitive 2022-08-10 08:40:29 +01:00
Alvis HT Tang cb5384bbd3 fix: update packages 2022-08-03 08:47:23 +01:00
Alvis HT Tang bc8037d290 chore(release): publish v3.4.0 2022-08-02 19:22:25 +01:00
Alvis HT Tang f3c1738abb fix(presetter): resolve presets as a tree not a list 2022-08-02 18:31:41 +01:00
Alvis HT Tang 530399e182 chore(release): publish v3.3.0 2022-07-12 12:54:01 +01:00
Alvis HT Tang 08c9487eed docs: update dependencies badges 2022-07-08 12:20:50 +01:00
Alvis HT Tang 7ea9b1bcee chore(release): publish v3.2.0 2022-05-18 15:15:41 +01:00
Alvis HT Tang 3c7d318f06 refactor: use American English 2022-05-16 21:35:20 +01:00
Alvis HT Tang bfd08357a2 chore: update package dependencies 2022-05-16 21:32:36 +01:00
Alvis HT Tang 7904e74115 chore(release): publish v3.1.1 2021-12-29 10:24:43 +00:00
Alvis HT Tang 5fb8c2c564 chore(release): publish v3.1.0 2021-12-28 18:45:33 +00:00
Alvis HT Tang d2a2ecc746 chore(release): publish v3.0.3 2021-11-03 09:41:58 +00:00
Alvis HT Tang a2496b3827 chore(release): publish v3.0.2 2021-11-03 08:46:42 +00:00
Alvis HT Tang 45d6ec3666 chore(release): publish v3.0.1 2021-10-14 09:20:40 +01:00
Alvis HT Tang e78ce2684b chore(release): publish v3.0.0 2021-10-04 14:13:53 +01:00
Alvis HT Tang daf36df63e fix(presetter): narrow types in directive's argument 2021-10-04 07:43:29 +01:00
Alvis HT Tang dd9f27c09f build: use presetter-preset-strict wherever possible 2021-09-30 21:04:39 +01:00
Alvis HT Tang 7f3e8e6870 refactor: rename presetter-preset to presetter-preset-essentials 2021-09-30 18:37:31 +01:00
Alvis HT Tang dfebcbe9a5 feat(preset-rollup): provide a preset for code bundling via rollup 2021-09-30 11:13:13 +01:00
18 changed files with 22740 additions and 1 deletions

19
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,19 @@
name: Build/Publish
on:
workflow_dispatch:
inputs:
debug_enabled:
description: Debug
type: boolean
default: false
push:
branches:
- master
- develop
- develop-*
jobs:
main:
uses: lumeweb/github-node-deploy-workflow/.github/workflows/main.yml@master
secrets: inherit

3
.presetterrc.json Normal file
View File

@ -0,0 +1,3 @@
{
"preset": ["presetter-preset-esm"]
}

1
.prettierignore Normal file
View File

@ -0,0 +1 @@
rollup.config.ts

68
.releaserc.json Normal file
View File

@ -0,0 +1,68 @@
{
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"releaseRules": [
{
"breaking": true,
"release": "major"
},
{
"revert": true,
"release": "patch"
},
{
"type": "feat",
"release": "minor"
},
{
"type": "fix",
"release": "patch"
},
{
"type": "perf",
"release": "patch"
},
{
"type": "dep",
"release": "patch"
},
{
"type": "refactor",
"release": "patch"
}
]
}
],
"@semantic-release/release-notes-generator",
[
"@semantic-release/changelog",
{
"changelogFile": "CHANGELOG.md"
}
],
"@semantic-release/npm",
[
"@semantic-release/git",
{
"assets": [
"package.json",
"CHANGELOG.md",
"npm-shrinkwrap.json"
]
}
]
],
"branches": [
"master",
{
"name": "develop",
"prerelease": true
},
{
"name": "develop-*",
"prerelease": true
}
]
}

274
CHANGELOG.md Normal file
View File

@ -0,0 +1,274 @@
# [4.1.0-develop.5](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.1.0-develop.4...v4.1.0-develop.5) (2023-07-02)
# [4.1.0-develop.4](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.1.0-develop.3...v4.1.0-develop.4) (2023-07-02)
# [4.1.0-develop.3](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.1.0-develop.2...v4.1.0-develop.3) (2023-07-02)
### Bug Fixes
* add inlineDynamicImports ([3e4d300](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/commit/3e4d3007b6908e8daecc907091ad22626e28782a))
# [4.1.0-develop.2](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.1.0-develop.1...v4.1.0-develop.2) (2023-07-02)
### Bug Fixes
* use optional chain syntax as the property might not be set ([2077d4e](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/commit/2077d4e70d37e7cf7f23a3db8e2d93ca414b1e2d))
# [4.1.0-develop.1](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.12...v4.1.0-develop.1) (2023-07-02)
### Bug Fixes
* inject browser options into node-resolve plugin if config.browser is true ([70a531e](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/commit/70a531e5aa88a68afb67b0ff7902fcfda2d6c298))
### Features
* add plugin-wasm ([57ef73d](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/commit/57ef73d9dcfcd835932db0393912eec770c22269))
## [4.0.2-develop.12](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.11...v4.0.2-develop.12) (2023-07-02)
### Bug Fixes
* need to split ts moduleResolution to the tsconfig file ([d31720c](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/commit/d31720ce140c7e2dafc4be4c673d38a2a2ba51be))
## [4.0.2-develop.11](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.10...v4.0.2-develop.11) (2023-07-02)
### Bug Fixes
* set TS moduleResolution to nodenext ([f1b82f8](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/commit/f1b82f85b1db77fffadb3452330b015ae9bf166b))
## [4.0.2-develop.10](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.9...v4.0.2-develop.10) (2023-07-02)
### Bug Fixes
* needs to extend presetter-preset-strict ([d526d8a](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/commit/d526d8ad6cb16833ba0ebea51eb6004515e1d91d))
## [4.0.2-develop.9](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.8...v4.0.2-develop.9) (2023-06-30)
### Bug Fixes
* outDir should not be an array and needs to be under compilerOptions ([f392036](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/commit/f3920365cc975fda24a481b005a00f3f737651ed))
## [4.0.2-develop.8](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.7...v4.0.2-develop.8) (2023-06-30)
### Bug Fixes
* buildSource needs to be src ([f1d13d0](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/commit/f1d13d00f1ea793205e9be25e7f21a9bb990bb5c))
## [4.0.2-develop.7](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.6...v4.0.2-develop.7) (2023-06-30)
### Bug Fixes
* typescript needs to come before rollup ([6be363c](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/commit/6be363c7c056360d17d7f5c448b0b0b5bea8b091))
## [4.0.2-develop.6](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.5...v4.0.2-develop.6) (2023-06-30)
### Bug Fixes
* add build:typescript:* to build script ([edf1960](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/commit/edf1960010004a72fba3b5b6d0649721977d594e))
## [4.0.2-develop.5](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.4...v4.0.2-develop.5) (2023-06-30)
### Bug Fixes
* dont pass file as argument ([41645d9](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/commit/41645d9661c1527719becdd6f0ff134126202a80))
## [4.0.2-develop.4](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.3...v4.0.2-develop.4) (2023-06-30)
### Bug Fixes
* update tsconfig.config ([a9001da](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/commit/a9001da2736ce97199abbd2350bbc20269670add))
## [4.0.2-develop.3](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.2...v4.0.2-develop.3) (2023-06-30)
### Bug Fixes
* add [@ts-nocheck](https://git.lumeweb.com/ts-nocheck) for rollup config ([cc72325](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/commit/cc72325e5f87a5c0c32e25f60b2af8a654dc8517))
## [4.0.2-develop.2](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.2-develop.1...v4.0.2-develop.2) (2023-06-30)
### Bug Fixes
* add files to package.json ([486314d](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/commit/486314de6b9d67a9eb9143c786cec3eac6ab7735))
## [4.0.2-develop.1](https://git.lumeweb.com/LumeWeb/presetter-preset-rollup/compare/v4.0.1...v4.0.2-develop.1) (2023-06-30)
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
## [4.0.1](https://github.com/alvis/presetter/compare/v4.0.0...v4.0.1) (2023-06-21)
# [4.0.0](https://github.com/alvis/presetter/compare/v3.5.5...v4.0.0) (2023-06-18)
### ✨ Features
* convert the whole project into ESM ([381c84f](https://github.com/alvis/presetter/commit/381c84f59605faf9ce6c2b3f81c2eea81bfebc61))
* **types:** separate types from presetter ([4ff3626](https://github.com/alvis/presetter/commit/4ff3626d915649208067b2235645e8534508f341))
### 🐛 Bug Fixes
* **preset-rollup:** inject NODE_ENV for build and develop stages ([b09ade5](https://github.com/alvis/presetter/commit/b09ade516250b8b5256d7f3d52ab1a30102607b5))
* **preset-rollup:** make the rollup preset compatible with ESM ([86154b8](https://github.com/alvis/presetter/commit/86154b8daaf7e3f97c1a93753416263fe7b086dc))
* update outdated packages ([bbaf33f](https://github.com/alvis/presetter/commit/bbaf33f0eaeaeca2c296cfc68207b4ff4632674f))
### 📦 Code Refactoring
* **preset-rollup:** normalize config in functional way ([f6b3815](https://github.com/alvis/presetter/commit/f6b3815a13309791852ba2442e0a48e6531f8d45))
### ♻️ Chores
* allow tests can be done individually ([b86f6ee](https://github.com/alvis/presetter/commit/b86f6eef689f7783a2a19841eaadf6e581dbb649))
* use pnpm for workspace management ([358d0d7](https://github.com/alvis/presetter/commit/358d0d77cdc2b37affb36931f13568464f1a46ab))
### 💎 Styles
* make any node build-in modules explicitly imported first ([90730f2](https://github.com/alvis/presetter/commit/90730f2dfd27a6a6f1fbceb26ac5fb974e11508e))
### Breaking changes
* - by default, client project emit ESM and for clarity preset-essentials has been renamed to preset-esm
- ts-node is removed in favor of a more powerful and less buggy tsx
## [3.5.5](https://github.com/alvis/presetter/compare/v3.5.4...v3.5.5) (2023-03-31)
## [3.5.4](https://github.com/alvis/presetter/compare/v3.5.3...v3.5.4) (2023-03-30)
## [3.5.3](https://github.com/alvis/presetter/compare/v3.5.2...v3.5.3) (2023-03-26)
## [3.5.2](https://github.com/alvis/presetter/compare/v3.5.1...v3.5.2) (2023-03-26)
## [3.5.1](https://github.com/alvis/presetter/compare/v3.5.0...v3.5.1) (2023-03-18)
# [3.5.0](https://github.com/alvis/presetter/compare/v3.4.1...v3.5.0) (2022-09-23)
### 🛠 Builds
* move .presetterrc to the root ([0eb17a0](https://github.com/alvis/presetter/commit/0eb17a058fa245faae96dcb017184460dae08b46))
### 📦 Code Refactoring
* **presetter:** remove dependency on fs-extra ([8810c56](https://github.com/alvis/presetter/commit/8810c568d1cf1de275b055916b6aeac450b43403))
* **rollup:** remove unnecessary async waits ([9d9c4c3](https://github.com/alvis/presetter/commit/9d9c4c3b5131548512574634414214380cb501f2))
## [3.4.1](https://github.com/alvis/presetter/compare/v3.4.0...v3.4.1) (2022-08-10)
### 🐛 Bug Fixes
* **presetter:** merge arrays only if the values are all primitive ([961f30c](https://github.com/alvis/presetter/commit/961f30c8fcbf9ba6f6fbf9e4d90cf0cb8c5a1069))
* update packages ([ec8307d](https://github.com/alvis/presetter/commit/ec8307d79468f8529b29a0f7b356b4368c03302c))
# [3.4.0](https://github.com/alvis/presetter/compare/v3.3.0...v3.4.0) (2022-08-02)
### 🐛 Bug Fixes
* **presetter:** resolve presets as a tree not a list ([0db5ff3](https://github.com/alvis/presetter/commit/0db5ff3b0020735591b3986c216578857dde3039))
# [3.3.0](https://github.com/alvis/presetter/compare/v3.2.0...v3.3.0) (2022-07-12)
### 📚 Documentation
* update dependencies badges ([94c084d](https://github.com/alvis/presetter/commit/94c084ddc39821106c9077bd4c12d1a7da9529eb))
# [3.2.0](https://github.com/alvis/presetter/compare/v3.1.1...v3.2.0) (2022-05-18)
### 📦 Code Refactoring
* use American English ([17315b7](https://github.com/alvis/presetter/commit/17315b78a9d65fb6193a609dd27b4d34454df1bc))
### ♻️ Chores
* update package dependencies ([4e50e0d](https://github.com/alvis/presetter/commit/4e50e0d2fce1bea470fbea62fc1eba52dccb3aed))
## [3.1.1](https://github.com/alvis/presetter/compare/v3.1.0...v3.1.1) (2021-12-29)
# [3.1.0](https://github.com/alvis/presetter/compare/v3.0.3...v3.1.0) (2021-12-28)
## [3.0.3](https://github.com/alvis/presetter/compare/v3.0.2...v3.0.3) (2021-11-03)
## [3.0.2](https://github.com/alvis/presetter/compare/v3.0.1...v3.0.2) (2021-11-03)
## [3.0.1](https://github.com/alvis/presetter/compare/v3.0.0...v3.0.1) (2021-10-14)
# [3.0.0](https://github.com/alvis/presetter/compare/v2.1.0...v3.0.0) (2021-10-04)
### ✨ Features
* **preset-rollup:** provide a preset for code bundling via rollup ([b0704b0](https://github.com/alvis/presetter/commit/b0704b0fe727c2724d7057d3803ecee49c230eff))
### 🐛 Bug Fixes
* **presetter:** narrow types in directive's argument ([c6de804](https://github.com/alvis/presetter/commit/c6de8044d4d9f584e3ef4ef688f81c08db425d1c))
### 🛠 Builds
* use presetter-preset-strict wherever possible ([4ff72a1](https://github.com/alvis/presetter/commit/4ff72a1a9730dfd4ad99d0a63dd4b005041ce759))
### 📦 Code Refactoring
* rename presetter-preset to presetter-preset-essentials ([b799587](https://github.com/alvis/presetter/commit/b7995871d85a1ccb8d2e43ba9b3a7e305de7a99b))

View File

@ -1,6 +1,7 @@
MIT License
Copyright (c) <year> <copyright holders>
Copyright (c) 2020 Alvis HT Tang
Copyright (c) 2023 Hammer Technologies LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

24
configs/rollup.yaml Normal file
View File

@ -0,0 +1,24 @@
input: '{source}/index.js'
output:
- file: '{output}/index.js'
format: cjs
sourcemap: true
inlineDynamicImports: true
plugins:
- '@apply @rollup/plugin-json[default]'
- '@apply @rollup/plugin-node-resolve[default]'
- - '@apply @rollup/plugin-commonjs[default]'
- extensions:
- .js
- .jsx
- .ts
- .tsx
- '@apply @rollup/plugin-graphql[default]'
- '@apply @rollup/plugin-image[default]'
- '@apply @rollup/plugin-yaml[default]'
- - '@apply rollup-plugin-postcss[default]'
- inject:
insertAt: top
- '@apply rollup-plugin-visualizer[visualizer]'
- - '@apply @rollup/plugin-wasm[default]'
- targetEnv: auto-inline

21440
npm-shrinkwrap.json generated Normal file

File diff suppressed because it is too large Load Diff

59
package.json Normal file
View File

@ -0,0 +1,59 @@
{
"name": "@lumeweb/presetter-preset-rollup",
"version": "4.1.0-develop.5",
"description": "An opinionated presetter preset for using rollup as a bundler",
"keywords": [
"presetter",
"preset"
],
"homepage": "https://github.com/alvis/presetter#readme",
"bugs": {
"url": "https://github.com/alvis/presetter/issues"
},
"license": "MIT",
"author": {
"name": "Alvis HT Tang",
"email": "alvis@hilbert.space"
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"type": "module",
"repository": {
"type": "git",
"url": "gitea@git.lumeweb.com:LumeWeb/presetter-preset-rollup.git"
},
"scripts": {
"prepare": "presetter bootstrap",
"build": "run build",
"semantic-release": "semantic-release"
},
"devDependencies": {
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"presetter": "^4.0.1",
"semantic-release": "^21.0.6"
},
"dependencies": {
"rollup": "^3.0.0",
"@rollup/plugin-commonjs": "^25.0.0",
"@rollup/plugin-graphql": "^2.0.0",
"@rollup/plugin-image": "^3.0.0",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.0",
"@rollup/plugin-yaml": "^4.0.0",
"rollup-plugin-postcss": "^4.0.0",
"rollup-plugin-visualizer": "^5.0.0",
"@rollup/plugin-wasm": "^6.1.3",
"presetter-preset-strict": "^4.0.1",
"presetter-types": "^4.0.1",
"type-fest": "^3.12.0"
},
"publishConfig": {
"access": "public"
},
"files": [
"lib",
"templates",
"configs"
]
}

117
source/index.ts Normal file
View File

@ -0,0 +1,117 @@
/*
* *** MIT LICENSE ***
* -------------------------------------------------------------------------
* This code may be modified and distributed under the MIT license.
* See the LICENSE file for details.
* -------------------------------------------------------------------------
*
* @summary Collection of preset assets for bundling a project with rollup
*
* @author Alvis HT Tang <alvis@hilbert.space>
* @license MIT
* @copyright Copyright (c) 2021 - All Rights Reserved.
* -------------------------------------------------------------------------
*/
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { loadFile, template } from 'presetter';
import { getRollupParameter } from './rollup';
import type { PresetAsset } from 'presetter-types';
import type { RollupConfig } from './rollup';
const DIR = fileURLToPath(dirname(import.meta.url));
// paths to the template directory
const TEMPLATES = resolve(DIR, '..', 'templates');
const CONFIGS = resolve(DIR, '..', 'configs');
/** config for this preset */
export type PresetConfig = {
rollup?: RollupConfig;
};
/** List of configurable variables */
export type Variable = {
/** the directory containing all source code (default: source) */
source: string;
/** the directory containing all the compiled files (default: lib) */
output: string;
buildSource: string;
};
export const DEFAULT_VARIABLE: Variable = {
source: 'build',
output: 'lib',
buildSource: 'src',
};
/**
* get the list of templates provided by this preset
* @returns list of preset templates
*/
export default function (): PresetAsset {
return {
extends: ['presetter-preset-strict'],
template: {
/* eslint-disable @typescript-eslint/naming-convention */
'rollup.config.ts': (context) => {
const content = loadFile(
resolve(TEMPLATES, 'rollup.config.ts'),
'text',
);
const variable = getRollupParameter(context);
return template(content, variable);
/* eslint-enable @typescript-eslint/naming-convention */
},
'tsconfig.config.json': resolve(TEMPLATES, 'tsconfig.config.yaml'),
},
scripts: resolve(TEMPLATES, 'scripts.yaml'),
noSymlinks: ['rollup.config.ts'],
supplementaryConfig: {
'gitignore': ['/rollup.config.ts'],
'rollup': (context) => {
const content = loadFile(resolve(CONFIGS, 'rollup.yaml')) as any;
if (context.custom?.config?.browser) {
let plugins = content.plugins.map((item) =>
Array.isArray(item) ? item[0] : item,
);
let resolvePluginName = plugins.filter((item) =>
item.includes('node-resolve'),
);
if (resolvePluginName.length) {
const index = plugins.indexOf(resolvePluginName[0]);
if (!Array.isArray(content.plugins[index])) {
content.plugins[index] = [content.plugins[index], {}];
}
content.plugins[index][1] = {
browser: true,
preferBuiltins: false,
};
}
}
return content;
},
'tsconfig': {
compilerOptions: {
moduleResolution: 'nodenext',
},
},
'tsconfig.build': {
include: ['{buildSource}'],
compilerOptions: {
outDir: '{source}',
},
},
},
variable: DEFAULT_VARIABLE,
};
}

115
source/plugin.ts Normal file
View File

@ -0,0 +1,115 @@
/*
* *** MIT LICENSE ***
* -------------------------------------------------------------------------
* This code may be modified and distributed under the MIT license.
* See the LICENSE file for details.
* -------------------------------------------------------------------------
*
* @summary Collection of plugin related helpers
*
* @author Alvis HT Tang <alvis@hilbert.space>
* @license MIT
* @copyright Copyright (c) 2021 - All Rights Reserved.
* -------------------------------------------------------------------------
*/
import { isDirective } from 'presetter';
import type { ApplyDirective, ImportDirective } from 'presetter';
import type { JsonObject } from 'type-fest';
/** full configuration about a plugin */
export type PluginConfiguration =
| [name: PluginHeader]
| [name: PluginHeader, options: PluginOptions | null];
/** specification of a plugin name and its handling direction (e.g. by invoking the function or just simply specify the name) */
export type PluginHeader = string | ApplyDirective;
/** options for a plugin */
export type PluginOptions = JsonObject | ApplyDirective | ImportDirective;
/** plugin configuration as an object */
export type PluginObject = Record<PluginHeader, PluginOptions | null>;
/** plugin configuration as an array */
export type PluginList = PluginListItem[];
/** possible types for individual item in a PluginList */
type PluginListItem = PluginHeader | [name: PluginHeader] | PluginConfiguration;
/** all possible configuration form for a collection of plugins */
export type PluginManifest = PluginList | PluginObject;
/**
* ensure that the given value is a valid PluginManifest
* @param value value to be tested
* @returns nothing if it's a pass
*/
export function assertPluginManifest(
value: unknown,
): asserts value is PluginManifest {
if (typeof value === 'object') {
if (Array.isArray(value)) {
return assertPluginList(value);
} else if (value !== null) {
return assertPluginObject(value as Record<string, unknown>);
}
}
throw new TypeError('plugin manifest is not in a supported format');
}
/**
* ensure that the given value is a valid PluginObject
* @param value value to be tested
*/
export function assertPluginObject(
value: Record<string, unknown>,
): asserts value is PluginObject {
// all values must be an object
if (
[...Object.values(value)].some(
(opt) => typeof opt !== 'object' && !isDirective(opt),
)
) {
throw new TypeError('all plugin options must be a object');
}
}
/**
* ensure that the given value is a valid PluginList
* @param value value to be tested
*/
export function assertPluginList(
value: unknown[],
): asserts value is PluginList {
for (const plugin of value) {
assertPluginListItem(plugin);
}
}
const PLUGIN_LIST_MAX_ITEMS = 2;
/**
* ensure that the given value is a valid PluginListItem
* @param value value to be tested
*/
export function assertPluginListItem(
value: unknown,
): asserts value is PluginListItem {
if (
typeof value !== 'string' &&
!(
Array.isArray(value) &&
value.length <= PLUGIN_LIST_MAX_ITEMS &&
typeof value[0] === 'string' &&
(isDirective(value[1]) ||
['undefined', 'object'].includes(typeof value[1]))
)
) {
throw new TypeError(
'a plugin manifest in an array form must be in either one of the following forms: string, [string], [string, object]',
);
}
}

216
source/rollup.ts Normal file
View File

@ -0,0 +1,216 @@
/*
* *** MIT LICENSE ***
* -------------------------------------------------------------------------
* This code may be modified and distributed under the MIT license.
* See the LICENSE file for details.
* -------------------------------------------------------------------------
*
* @summary Collection of helpers for rollup
*
* @author Alvis HT Tang <alvis@hilbert.space>
* @license MIT
* @copyright Copyright (c) 2021 - All Rights Reserved.
* -------------------------------------------------------------------------
*/
import {
isDirective,
isJSON,
merge,
resolveDirective,
template,
} from 'presetter';
import { assertPluginManifest } from './plugin';
import type { ApplyDirective, ImportDirective } from 'presetter';
import type { ResolvedPresetContext } from 'presetter-types';
import type {
PluginConfiguration,
PluginList,
PluginManifest,
PluginObject,
} from './plugin';
/** preset configuration for rollup */
export interface RollupConfig {
[index: string]: unknown | RollupConfig;
/** list of plugin and its options */
plugins?: PluginManifest | ApplyDirective | ImportDirective;
}
/** genuine configuration that rollup would take, making sure all plugins are a list */
interface TrueRollupConfig {
[index: string]: unknown | TrueRollupConfig;
/** list of plugin and its options */
plugins?: PluginConfiguration[];
}
/** transformed configuration for rollup, with all plugins represented by an object */
interface IntermediateRollupConfig {
[index: string]: unknown | IntermediateRollupConfig;
/** list of plugin and its options */
plugins?: PluginObject;
}
/**
* get template parameters for rollup
* @param context context about the build environment
* @returns template parameter related to rollup
*/
export function getRollupParameter(
context: ResolvedPresetContext,
): Record<'rollupImport' | 'rollupExport', string> {
const { config, variable } = context.custom;
const normalizedConfig = template(
normalizeConfig(transformConfig({ ...config.rollup })),
variable,
);
return generateRollupParameter(normalizedConfig, context);
}
/**
* generate template parameters for rollup
* @param config normalized rollup config
* @param context context about the build environment
* @returns template parameter related to rollup
*/
function generateRollupParameter(
config: TrueRollupConfig,
context: ResolvedPresetContext,
): Record<'rollupImport' | 'rollupExport', string> {
const { importMap, stringifiedConfig } = resolveDirective(config, context);
// generate import statements
const rollupImport = Object.entries(importMap)
.map(([name, resolved]) => `import * as ${resolved} from '${name}';`)
.join('\n');
// generate export statements
const rollupExport = `export default ${stringifiedConfig}`;
return { rollupImport, rollupExport };
}
/**
* normalize rollup config with all plugins represented as a list
* @param config transformed config
* @returns config that rollup would take
*/
function normalizeConfig(config: IntermediateRollupConfig): TrueRollupConfig {
return Object.fromEntries(
Object.entries(config).map(([key, value]): [string, unknown] => {
return [
key,
isDirective(value) ? value : normalizeConfigValue(key, value),
];
}),
);
}
/**
* try to normalize any nested configuration
* @param key field name
* @param value value of a field
* @returns normalized value
*/
function normalizeConfigValue(key: string, value: unknown): unknown {
switch (key) {
case 'plugins':
return [
...Object.entries(value as PluginObject)
.filter(([_, options]) => options !== null)
.map(([plugin, options]) =>
[plugin, normalizeConfigValue(plugin, options)].filter(
(element) => element !== undefined,
),
),
];
default:
return isJSON(value)
? normalizeConfig(value as IntermediateRollupConfig)
: value;
}
}
/**
* transform rollup config with plugins represented by an object for better merging
* @param config rollup config in .presetterrc
* @returns transformed config
*/
function transformConfig(
config: Record<string, any>,
): IntermediateRollupConfig {
return Object.fromEntries(
Object.entries(config).map(([key, value]): [string, unknown] => {
return [
key,
isDirective(value) ? value : transformConfigValue(key, value),
];
}),
);
}
/**
* try to transform any nested configuration
* @param key field name
* @param value value of a field
* @returns transformed value
*/
function transformConfigValue(key: string, value: unknown): unknown {
switch (key) {
case 'plugins':
assertPluginManifest(value);
return objectifyPlugins(value);
default:
return isJSON(value) ? transformConfig(value) : value;
}
}
/**
* objectify rollup plugins
* @param plugins rollup plugin config
* @returns normalized plugin config
*/
function objectifyPlugins(
plugins: PluginManifest,
): IntermediateRollupConfig['plugins'] {
const pluginList: PluginConfiguration[] = Array.isArray(plugins)
? arrayToPluginConfiguration(plugins)
: objectToPluginConfiguration(plugins);
return pluginList.reduce(
(normalizedPlugin, [name, options]) =>
merge(normalizedPlugin, { [name]: options }),
{},
);
}
/**
* normalize rollup plugin config in array form
* @param plugins rollup plugin config in array form
* @returns normalized plugin config
*/
function arrayToPluginConfiguration(
plugins: PluginList,
): PluginConfiguration[] {
return plugins.map((plugin) =>
typeof plugin === 'string' ? [plugin] : plugin,
);
}
/**
* normalize rollup plugin config in object form
* @param plugins rollup plugin config in object form
* @returns normalized plugin config
*/
function objectToPluginConfiguration(
plugins: PluginObject,
): PluginConfiguration[] {
return [...Object.entries(plugins)];
}

62
spec/index.spec.ts Normal file
View File

@ -0,0 +1,62 @@
/*
* *** MIT LICENSE ***
* -------------------------------------------------------------------------
* This code may be modified and distributed under the MIT license.
* See the LICENSE file for details.
* -------------------------------------------------------------------------
*
* @summary Tests on config generation
*
* @author Alvis HT Tang <alvis@hilbert.space>
* @license MIT
* @copyright Copyright (c) 2020 - All Rights Reserved.
* -------------------------------------------------------------------------
*/
import { existsSync, readdirSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import * as pathNode from 'node:path';
import { fileURLToPath } from 'node:url';
import { jest } from '@jest/globals';
const __dir = fileURLToPath(dirname(import.meta.url));
jest.unstable_mockModule('node:path', () => ({
...pathNode,
// spy on resolve to check if a template is referenced
resolve: jest.fn(resolve),
}));
const { resolve: resolveSpyed } = await import('node:path');
const { loadDynamicMap, resolveContext } = await import('presetter');
const { default: getPresetAsset } = await import('#index');
describe('fn:getPresetAsset', () => {
it('use all templates', async () => {
const asset = await getPresetAsset();
const context = await resolveContext({
graph: [{ name: 'preset', asset, nodes: [] }],
context: {
target: { name: 'preset', root: '/', package: {} },
custom: { preset: 'preset' },
},
});
// load all potential dynamic content
await loadDynamicMap(asset.supplementaryConfig, context);
await loadDynamicMap(asset.template, context);
const CONFIGS = resolve(__dir, '..', 'configs');
const configs = (existsSync(CONFIGS) && readdirSync(CONFIGS)) || [];
const TEMPLATES = resolve(__dir, '..', 'templates');
const templates = (existsSync(TEMPLATES) && readdirSync(TEMPLATES)) || [];
for (const path of configs) {
expect(resolveSpyed).toBeCalledWith(CONFIGS, path);
}
for (const path of templates) {
expect(resolveSpyed).toBeCalledWith(TEMPLATES, path);
}
});
});

101
spec/plugin.spec.ts Normal file
View File

@ -0,0 +1,101 @@
/*
* *** MIT LICENSE ***
* -------------------------------------------------------------------------
* This code may be modified and distributed under the MIT license.
* See the LICENSE file for details.
* -------------------------------------------------------------------------
*
* @summary Tests on plugin related helpers
*
* @author Alvis HT Tang <alvis@hilbert.space>
* @license MIT
* @copyright Copyright (c) 2021 - All Rights Reserved.
* -------------------------------------------------------------------------
*/
import {
assertPluginList,
assertPluginListItem,
assertPluginObject,
assertPluginManifest,
} from '#plugin';
describe('fn:assertPluginListItem', () => {
it('pass with just a string', () => {
expect(() => assertPluginListItem('plugin')).not.toThrow();
});
it('pass with a string in an array', () => {
expect(() => assertPluginListItem(['plugin'])).not.toThrow();
});
it('pass with a string and its options in an array', () => {
expect(() =>
assertPluginListItem(['plugin', { options: true }]),
).not.toThrow();
});
it('fails with a non-string header', () => {
expect(() => assertPluginListItem([0])).toThrow(TypeError);
});
it('fails with an array more than 2 items', () => {
expect(() =>
assertPluginListItem(['plugin', { options: true }, 'extra']),
).toThrow(TypeError);
});
});
describe('fn:assertPluginList', () => {
it('pass with a valid plugin configuration list', () => {
expect(() =>
assertPluginList(['plugin', ['plugin'], ['plugin', { options: true }]]),
).not.toThrow();
});
it('fail with any invalid plugin configurations', () => {
expect(() =>
assertPluginList([
'plugin',
['plugin'],
['plugin', { options: true }],
{ invalid: true },
]),
).toThrow(TypeError);
});
});
describe('fn:assertPluginObject', () => {
it('pass with a valid plugin configuration object', () => {
expect(() =>
assertPluginObject({ plugin: { options: true } }),
).not.toThrow();
});
it('fail with any invalid plugin options', () => {
expect(() => assertPluginObject({ plugin: true })).toThrow(TypeError);
});
});
describe('fn:assertPluginManifest', () => {
it('pass with a valid plugin configuration object', () => {
expect(() =>
assertPluginManifest({ plugin: { options: true } }),
).not.toThrow();
});
it('pass with a valid plugin configuration list', () => {
expect(() =>
assertPluginManifest([
'plugin',
['plugin'],
['plugin', { options: true }],
]),
).not.toThrow();
});
it('fail with any invalid manifest', () => {
expect(() => assertPluginManifest(null)).toThrow(TypeError);
expect(() => assertPluginManifest('invalid')).toThrow(TypeError);
});
});

220
spec/rollup.spec.ts Normal file
View File

@ -0,0 +1,220 @@
/*
* *** MIT LICENSE ***
* -------------------------------------------------------------------------
* This code may be modified and distributed under the MIT license.
* See the LICENSE file for details.
* -------------------------------------------------------------------------
*
* @summary Tests on the helpers for rollup
*
* @author Alvis HT Tang <alvis@hilbert.space>
* @license MIT
* @copyright Copyright (c) 2021 - All Rights Reserved.
* -------------------------------------------------------------------------
*/
import { getRollupParameter } from '#rollup';
import type { Config, ResolvedPresetContext } from 'presetter-types';
describe('fn:getRollupParameter', () => {
const generateContext = (config?: Config): ResolvedPresetContext => ({
target: { name: 'target', root: '/path/to/target', package: {} },
custom: {
preset: 'preset',
config: config ? { rollup: config } : {},
noSymlinks: [],
variable: {},
},
});
it('add plugins by importing from another config files', async () => {
expect(
await getRollupParameter(
generateContext({
plugins: '@import config[plugins]',
}),
),
).toEqual({
rollupImport: `import * as import0 from 'config';`,
rollupExport: 'export default {"plugins": import0.plugins}',
});
});
it('add a plugin by adding the plugin in the object form, using the supplied options', async () => {
expect(
await getRollupParameter(
generateContext({
plugins: { '@apply newPlugin': { name: 'newPlugin' } },
}),
),
).toEqual({
rollupImport: `import * as import0 from 'newPlugin';`,
rollupExport:
'export default {"plugins": [import0(...([{"name": "newPlugin"}] as const))]}',
});
});
it('add a plugin by just the plugin name, using everything default', async () => {
expect(
await getRollupParameter(
generateContext({
plugins: ['@apply newPlugin'],
}),
),
).toEqual({
rollupImport: `import * as import0 from 'newPlugin';`,
rollupExport: 'export default {"plugins": [import0(...([] as const))]}',
});
});
it('add a plugin by adding the plugin in the array form, using everything default', async () => {
expect(
await getRollupParameter(
generateContext({
plugins: [['@apply newPlugin']],
}),
),
).toEqual({
rollupImport: `import * as import0 from 'newPlugin';`,
rollupExport: 'export default {"plugins": [import0(...([] as const))]}',
});
});
it('add a plugin by adding the plugin in the array form, using the supplied options', async () => {
expect(
await getRollupParameter(
generateContext({
plugins: [['@apply newPlugin', { name: 'newPlugin' }]],
}),
),
).toEqual({
rollupImport: `import * as import0 from 'newPlugin';`,
rollupExport:
'export default {"plugins": [import0(...([{"name": "newPlugin"}] as const))]}',
});
});
it('remove a plugin by setting the plugin config as null', async () => {
expect(
await getRollupParameter(
generateContext({
plugins: {
'@apply pluginWithOptions': null,
},
}),
),
).toEqual({
rollupImport: ``,
rollupExport: 'export default {"plugins": []}',
});
});
it('add a plugin from a named import', async () => {
expect(
await getRollupParameter(
generateContext({
plugins: {
'@apply pluginWithOptions': null,
'@apply pluginWithoutOptions': null,
'@apply newPlugin[plugin]': { options: true },
},
}),
),
).toEqual({
rollupImport: `import * as import0 from 'newPlugin';`,
rollupExport:
'export default {"plugins": [import0.plugin(...([{"options": true}] as const))]}',
});
});
it('generate default parameters if no further config is given', async () => {
expect(await getRollupParameter(generateContext())).toEqual({
rollupImport: ``,
rollupExport: 'export default {}',
});
});
it('generate config with extra options other than plugins', async () => {
expect(
await getRollupParameter(
generateContext({
cache: null,
extra: { options: true },
external: ['import1', 'import2'],
}),
),
).toEqual({
rollupImport: ``,
rollupExport:
'export default {"cache": null, "extra": {"options": true}, "external": ["import1", "import2"]}',
});
});
it('generate extra import statements for imports within plugin options', async () => {
expect(
await getRollupParameter(
generateContext({
plugins: {
'@apply pluginWithOptions': '@import another',
'@apply pluginWithoutOptions': '@import another',
},
}),
),
).toEqual({
rollupImport: `import * as import0 from 'another';\nimport * as import1 from 'pluginWithOptions';\nimport * as import2 from 'pluginWithoutOptions';`,
rollupExport: `export default {"plugins": [import1(...([import0] as const)), import2(...([import0] as const))]}`,
});
expect(
await getRollupParameter(
generateContext({
plugins: [
['@apply pluginWithOptions', '@import another'],
['@apply pluginWithoutOptions', '@import another'],
],
}),
),
).toEqual({
rollupImport: `import * as import0 from 'another';\nimport * as import1 from 'pluginWithOptions';\nimport * as import2 from 'pluginWithoutOptions';`,
rollupExport: `export default {"plugins": [import1(...([import0] as const)), import2(...([import0] as const))]}`,
});
});
it('generate only one import statement per unique import', async () => {
expect(
await getRollupParameter(
generateContext({
plugins: {
'@apply pluginWithOptions': null,
'@apply pluginWithoutOptions': null,
'@apply plugin0': '@import another[export0]',
'@apply plugin1': '@import another[export1]',
},
}),
),
).toEqual({
rollupImport: `import * as import0 from 'another';\nimport * as import1 from 'plugin0';\nimport * as import2 from 'plugin1';`,
rollupExport: `export default {"plugins": [import1(...([import0.export0] as const)), import2(...([import0.export1] as const))]}`,
});
});
it('support nested plugin declaration', async () => {
expect(
await getRollupParameter(
generateContext({
plugins: {
'@apply pluginWithOptions': null,
'@apply pluginWithoutOptions': null,
'@apply plugin0': {
plugins: { another: '@import options[export0]' },
},
},
}),
),
).toEqual({
rollupImport: `import * as import0 from 'options';\nimport * as import1 from 'plugin0';`,
rollupExport: `export default {"plugins": [import1(...([{"plugins": [["another", import0.export0]]}] as const))]}`,
});
});
});

View File

@ -0,0 +1,4 @@
// @ts-nocheck
{rollupImport}
{rollupExport}

7
templates/scripts.yaml Normal file
View File

@ -0,0 +1,7 @@
# replace the `prepare` template from presetter-preset
# so that the build procedure will not be triggered upon package installation
build: cross-env NODE_ENV=production run-s clean build:typescript:* build:rollup-config build:rollup
build:rollup-config: tsc -p tsconfig.config.json
build:rollup: rollup --config rollup.config.js
develop: cross-env NODE_ENV=development run-s "build:rollup -- --watch {@}" --
clean:buildOutput: shx rm -rf {source}

View File

@ -0,0 +1,8 @@
extends: .
include:
- 'rollup.config.ts'
compilerOptions:
# emittance
outDir: '.'
noEmit: false
declaration: false