kintone-plugin-ide 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 oshio0929
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 oshio0929
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,123 +1,123 @@
1
- # kintone-plugin-ide
2
-
3
- kintone のレコード1件を、プラグイン1つの開発環境にする。
4
- エディタ(modern-monaco)・ファイルツリー・ターミナル・npm・esbuild のビルド・署名・インストールまで、ブラウザだけで完結する。
5
-
6
- ## 使い方
7
-
8
- アプリの「JavaScript / CSSでカスタマイズ」に、次の JS ファイルを1つ入れる。
9
-
10
- ```js
11
- (async () => {
12
- const { setup } = await import('https://esm.sh/kintone-plugin-ide@0.3.0');
13
- setup({
14
- installHosts: ['example.cybozu.com'], // インストールしてよい環境
15
- // fields: { source: 'source_zip', key: 'private_key' }, // フィールドコードを変えたとき
16
- });
17
- })();
18
- ```
19
-
20
- - バージョンは必ず固定して読む(`@0.3.0`)。範囲で読むと、公開のたびに動きが変わる
21
- - jsDelivr なら `https://cdn.jsdelivr.net/npm/kintone-plugin-ide@0.3.0/+esm`
22
- - 1ファイル版: `dist/kintone-plugin-ide.iife.js` を入れて、別のファイルで `KintonePluginIDE.setup({ ... })`
23
-
24
- ## アプリに要るフィールド
25
-
26
- | コード(既定) | 種類 | 中身 |
27
- |---|---|---|
28
- | source_zip | 添付ファイル | ソース一式の zip(保存のたびに置き換え。node_modules は入れない) |
29
- | private_key | 添付ファイル | 秘密鍵(.ppk)。空なら最初のパッケージで作る。閲覧権限を絞ること |
30
- | plugin_zip | 添付ファイル | 最後に作ったプラグイン |
31
- | plugin_id | 文字列(1行) | プラグインID |
32
- | test_app | 数値 | インストール後に反映するアプリ(任意) |
33
-
34
- ## 画面を使わない部品
35
-
36
- ```js
37
- import { buildPlugin, generateKey, pack, unpack } from 'kintone-plugin-ide';
38
- ```
39
-
40
- 署名(`pack`)は公式のパッカーと同じ結果になることを確認済み。
41
-
42
- ## 開発
43
-
44
- ```
45
- npm ci
46
- npm run build # dist/index.js と dist/kintone-plugin-ide.iife.js
47
- npm test
48
- ```
49
-
50
- 公開: `package.json` の version を上げて `v<version>` のタグを push すると、GitHub Actions が npm に段階公開する。npmjs.com で承認すると公開される。
51
-
52
- ## ビルドできるファイル
53
-
54
- | 拡張子 | 変換 | コンパイラ(使う時に esm.sh から) |
55
- |---|---|---|
56
- | .ts .tsx .js .jsx .json .css | esbuild がそのまま | — |
57
- | .svelte | Svelte 5 のコンポーネント(CSS は実行時に差し込む) | package.json の svelte と同じバージョンの svelte/compiler |
58
- | .svelte.ts .svelte.js | ルーン入りモジュール(TS を剥がしてから compileModule) | 同上 |
59
- | .vue | SFC(script setup / TS / scoped / `<style lang="scss">`) | package.json の vue と同じバージョンの @vue/compiler-sfc |
60
- | .scss .sass | CSS(@use / @import は IDE のファイルから) | sass |
61
- | .less | CSS(@import は IDE のファイルから) | less |
62
- | .yaml .yml | `export default {...}` | js-yaml |
63
-
64
- - `css/desktop.css` は `src/desktop.{css,scss,sass,less}` から作る。
65
- - svelte / vue / react / preact などは「ランタイムを共有するパッケージ」として、esm.sh の分割されたモジュールのまま esbuild にまとめる(サブパスごとに丸ごと抱え込むと二重に入って壊れるため)。node_modules には印の package.json だけ置く。取ったモジュールは IndexedDB に残る。
66
- - ターミナルの `sample svelte` / `sample vue` でサンプルに入れ替えられる。
67
- - エディタでは `*.svelte` `*.vue` `*.yaml` の import と、Svelte のルーン(`$state` など)に型を用意してある(`kintone-plugin-ide-env.d.ts`、仮のファイル)。
68
- - svelte の型は `declare module 'svelte'` の形でまとめて配られていて、esm.sh 経由だと壊れるので、jsDelivr から型ファイルを取って上の仮のファイルに足している。
69
-
70
- ## エディタの言語サービス
71
-
72
- - modern-monaco は 0.3.8 に固定(0.4 系は kintone 上で言語サービスが動かなかった)。
73
- - `ide/workspace-fs.js` が、IDE のファイルを modern-monaco の Workspace に見せる。ファイルに無ければ次を「あることに」する:
74
- - `tsconfig.json` … `types` に @kintone/dts-gen の kintone.d.ts(URL)。自分で置けばそちらが優先
75
- - `index.html` … import map。package.json の依存を esm.sh に向け(型も esm.sh から)、拡張子を省いた相対 import(`./lib/banner`)を scopes で `.ts` に向ける
76
- - 型チェックは、エディタのマーカーの更新が止まるまで待ってから数える(初回は型の取得で数秒かかる)。
77
-
78
- ## 自分のエディタと合体させるとき
79
-
80
- - `src/build/` `src/packer/` `src/npm/` `src/kintone/` は画面に依存しない。`files`(path → text の Map)を渡せば動く。
81
- - ライブラリは `src/deps.js` で CDN から動的 import している。npm から入れてバンドルするなら、
82
- そこを `import('modern-monaco')` のような素の指定に変えて、build.mjs の `external` を外す。
83
- - `ctx` は「IDE の部品どうしの共有の入れ物」。部品を差し替えるときは、同じ名前の関数を ctx に足せばいい。
84
-
85
- ## node_modules の扱い
86
-
87
- - `npm install dayjs` → esm.sh から取ってきて、依存ごと1ファイルにして `node_modules/dayjs/index.mjs` に置く。ツリーに出る(読み取り専用)。
88
- - `dayjs/plugin/utc` のようなサブパスは、ビルドで使った時に取ってきて `node_modules/dayjs/plugin/utc.mjs` に置く。
89
- - ビルドすると esbuild が `js/*.js` に入れる。プラグインにはそれで入る。node_modules そのものは zip にもレコードにも入れない。
90
- - 取ってきたものはブラウザの IndexedDB に `name@version` 単位で残るので、2回目からは通信しない。開いた時に package.json の通りにそろえ直す。
91
- - 気をつけること: パッケージごとに依存を全部抱え込むので、react と react-dom のように同じものを共有するパッケージは二重に入る。
92
-
93
- ## ディレクトリ
94
-
95
- ```
96
- src/
97
- index.js 入口。詳細画面に「IDEで開く」を出す
98
- config.js フィールドコード・INSTALL_HOSTS・CDN のバージョン ← 環境ごとに変えるのはここ
99
- deps.js 外部ライブラリの読み込み(全部ここに集めてある)
100
- util/ bytes / path / dom / settings / idb(IndexedDB)
101
- kintone/
102
- api.js REST・ファイルの上げ下ろし
103
- plugin.js インストール / 更新・テスト用アプリへの追加と反映
104
- packer/packer.js 署名つきパッケージ(Web Crypto + fflate)と、プラグイン zip の検証・展開
105
- npm/
106
- registry.js package.json・npm registry・esm.sh の URL
107
- vendor.js esm.sh から取ってきて1ファイルの ESM にし、node_modules/ に置く(IndexedDB にキャッシュ)
108
- build/
109
- http-plugin.js esbuild: http(s) の import を fetch
110
- vfs-plugin.js esbuild: IDE のファイル(Map)と node_modules/ を読む
111
- build.js manifest.json → ビルド → manifest 検証 → contents.zip
112
- ide/
113
- index.js 組み立て(各部品が ctx に関数を足していく)・開く/閉じる
114
- state.js ファイル・保存済み・空フォルダ・未保存の判定・レコードの行
115
- layout.js css.js 骨組み・状態バー・処理の直列化(run)
116
- terminal.js xterm + readline・ログ・リンク
117
- tree.js @pierre/trees・メニュー・ファイル/フォルダ操作
118
- editor.js modern-monaco・差分・型チェック・整形
119
- commands.js ターミナルのコマンド
120
- sample.js 最初に入れるサンプル
121
- actions/ save / release(ビルド〜インストール)/ zip / npm / misc
122
- ```
123
-
1
+ # kintone-plugin-ide
2
+
3
+ kintone のレコード1件を、プラグイン1つの開発環境にする。
4
+ エディタ(modern-monaco)・ファイルツリー・ターミナル・npm・esbuild のビルド・署名・インストールまで、ブラウザだけで完結する。
5
+
6
+ ## 使い方
7
+
8
+ アプリの「JavaScript / CSSでカスタマイズ」に、次の JS ファイルを1つ入れる。
9
+
10
+ ```js
11
+ (async () => {
12
+ const { setup } = await import('https://esm.sh/kintone-plugin-ide@0.3.1');
13
+ setup({
14
+ installHosts: ['example.cybozu.com'], // インストールしてよい環境
15
+ // fields: { source: 'source_zip', key: 'private_key' }, // フィールドコードを変えたとき
16
+ });
17
+ })();
18
+ ```
19
+
20
+ - バージョンは必ず固定して読む(`@0.3.0`)。範囲で読むと、公開のたびに動きが変わる
21
+ - jsDelivr なら `https://cdn.jsdelivr.net/npm/kintone-plugin-ide@0.3.1/+esm`
22
+ - 1ファイル版: `dist/kintone-plugin-ide.iife.js` を入れて、別のファイルで `KintonePluginIDE.setup({ ... })`
23
+
24
+ ## アプリに要るフィールド
25
+
26
+ | コード(既定) | 種類 | 中身 |
27
+ |---|---|---|
28
+ | source_zip | 添付ファイル | ソース一式の zip(保存のたびに置き換え。node_modules は入れない) |
29
+ | private_key | 添付ファイル | 秘密鍵(.ppk)。空なら最初のパッケージで作る。閲覧権限を絞ること |
30
+ | plugin_zip | 添付ファイル | 最後に作ったプラグイン |
31
+ | plugin_id | 文字列(1行) | プラグインID |
32
+ | test_app | 数値 | インストール後に反映するアプリ(任意) |
33
+
34
+ ## 画面を使わない部品
35
+
36
+ ```js
37
+ import { buildPlugin, generateKey, pack, unpack } from 'kintone-plugin-ide';
38
+ ```
39
+
40
+ 署名(`pack`)は公式のパッカーと同じ結果になることを確認済み。
41
+
42
+ ## 開発
43
+
44
+ ```
45
+ npm ci
46
+ npm run build # dist/index.js と dist/kintone-plugin-ide.iife.js
47
+ npm test
48
+ ```
49
+
50
+ 公開: `package.json` の version を上げて `v<version>` のタグを push すると、GitHub Actions が npm に段階公開する。npmjs.com で承認すると公開される。
51
+
52
+ ## ビルドできるファイル
53
+
54
+ | 拡張子 | 変換 | コンパイラ(使う時に esm.sh から) |
55
+ |---|---|---|
56
+ | .ts .tsx .js .jsx .json .css | esbuild がそのまま | — |
57
+ | .svelte | Svelte 5 のコンポーネント(CSS は実行時に差し込む) | package.json の svelte と同じバージョンの svelte/compiler |
58
+ | .svelte.ts .svelte.js | ルーン入りモジュール(TS を剥がしてから compileModule) | 同上 |
59
+ | .vue | SFC(script setup / TS / scoped / `<style lang="scss">`) | package.json の vue と同じバージョンの @vue/compiler-sfc |
60
+ | .scss .sass | CSS(@use / @import は IDE のファイルから) | sass |
61
+ | .less | CSS(@import は IDE のファイルから) | less |
62
+ | .yaml .yml | `export default {...}` | js-yaml |
63
+
64
+ - `css/desktop.css` は `src/desktop.{css,scss,sass,less}` から作る。
65
+ - svelte / vue / react / preact などは「ランタイムを共有するパッケージ」として、esm.sh の分割されたモジュールのまま esbuild にまとめる(サブパスごとに丸ごと抱え込むと二重に入って壊れるため)。node_modules には印の package.json だけ置く。取ったモジュールは IndexedDB に残る。
66
+ - ターミナルの `sample svelte` / `sample vue` でサンプルに入れ替えられる。
67
+ - エディタでは `*.svelte` `*.vue` `*.yaml` の import と、Svelte のルーン(`$state` など)に型を用意してある(`kintone-plugin-ide-env.d.ts`、仮のファイル)。
68
+ - svelte の型は `declare module 'svelte'` の形でまとめて配られていて、esm.sh 経由だと壊れるので、jsDelivr から型ファイルを取って上の仮のファイルに足している。
69
+
70
+ ## エディタの言語サービス
71
+
72
+ - modern-monaco は 0.3.8 に固定(0.4 系は kintone 上で言語サービスが動かなかった)。
73
+ - `ide/workspace-fs.js` が、IDE のファイルを modern-monaco の Workspace に見せる。ファイルに無ければ次を「あることに」する:
74
+ - `tsconfig.json` … `types` に @kintone/dts-gen の kintone.d.ts(URL)。自分で置けばそちらが優先
75
+ - `index.html` … import map。package.json の依存を esm.sh に向け(型も esm.sh から)、拡張子を省いた相対 import(`./lib/banner`)を scopes で `.ts` に向ける
76
+ - 型チェックは、エディタのマーカーの更新が止まるまで待ってから数える(初回は型の取得で数秒かかる)。
77
+
78
+ ## 自分のエディタと合体させるとき
79
+
80
+ - `src/build/` `src/packer/` `src/npm/` `src/kintone/` は画面に依存しない。`files`(path → text の Map)を渡せば動く。
81
+ - ライブラリは `src/deps.js` で CDN から動的 import している。npm から入れてバンドルするなら、
82
+ そこを `import('modern-monaco')` のような素の指定に変えて、build.mjs の `external` を外す。
83
+ - `ctx` は「IDE の部品どうしの共有の入れ物」。部品を差し替えるときは、同じ名前の関数を ctx に足せばいい。
84
+
85
+ ## node_modules の扱い
86
+
87
+ - `npm install dayjs` → esm.sh から取ってきて、依存ごと1ファイルにして `node_modules/dayjs/index.mjs` に置く。ツリーに出る(読み取り専用)。
88
+ - `dayjs/plugin/utc` のようなサブパスは、ビルドで使った時に取ってきて `node_modules/dayjs/plugin/utc.mjs` に置く。
89
+ - ビルドすると esbuild が `js/*.js` に入れる。プラグインにはそれで入る。node_modules そのものは zip にもレコードにも入れない。
90
+ - 取ってきたものはブラウザの IndexedDB に `name@version` 単位で残るので、2回目からは通信しない。開いた時に package.json の通りにそろえ直す。
91
+ - 気をつけること: パッケージごとに依存を全部抱え込むので、react と react-dom のように同じものを共有するパッケージは二重に入る。
92
+
93
+ ## ディレクトリ
94
+
95
+ ```
96
+ src/
97
+ index.js 入口。詳細画面に「IDEで開く」を出す
98
+ config.js フィールドコード・INSTALL_HOSTS・CDN のバージョン ← 環境ごとに変えるのはここ
99
+ deps.js 外部ライブラリの読み込み(全部ここに集めてある)
100
+ util/ bytes / path / dom / settings / idb(IndexedDB)
101
+ kintone/
102
+ api.js REST・ファイルの上げ下ろし
103
+ plugin.js インストール / 更新・テスト用アプリへの追加と反映
104
+ packer/packer.js 署名つきパッケージ(Web Crypto + fflate)と、プラグイン zip の検証・展開
105
+ npm/
106
+ registry.js package.json・npm registry・esm.sh の URL
107
+ vendor.js esm.sh から取ってきて1ファイルの ESM にし、node_modules/ に置く(IndexedDB にキャッシュ)
108
+ build/
109
+ http-plugin.js esbuild: http(s) の import を fetch
110
+ vfs-plugin.js esbuild: IDE のファイル(Map)と node_modules/ を読む
111
+ build.js manifest.json → ビルド → manifest 検証 → contents.zip
112
+ ide/
113
+ index.js 組み立て(各部品が ctx に関数を足していく)・開く/閉じる
114
+ state.js ファイル・保存済み・空フォルダ・未保存の判定・レコードの行
115
+ layout.js css.js 骨組み・状態バー・処理の直列化(run)
116
+ terminal.js xterm + readline・ログ・リンク
117
+ tree.js @pierre/trees・メニュー・ファイル/フォルダ操作
118
+ editor.js modern-monaco・差分・型チェック・整形
119
+ commands.js ターミナルのコマンド
120
+ sample.js 最初に入れるサンプル
121
+ actions/ save / release(ビルド〜インストール)/ zip / npm / misc
122
+ ```
123
+
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /* kintone-plugin-ide v0.3.0 (src/ からビルド) */
1
+ /* kintone-plugin-ide v0.3.1 (src/ からビルド) */
2
2
  var __defProp = Object.defineProperty;
3
3
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -1,4 +1,4 @@
1
- /* kintone-plugin-ide v0.3.0 (src/ からビルド) */
1
+ /* kintone-plugin-ide v0.3.1 (src/ からビルド) */
2
2
  var KintonePluginIDE = (() => {
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
package/package.json CHANGED
@@ -1,59 +1,59 @@
1
- {
2
- "name": "kintone-plugin-ide",
3
- "version": "0.3.0",
4
- "description": "kintone のレコードを、そのままプラグインの開発環境(エディタ・ターミナル・ビルド・署名・インストール)にする",
5
- "type": "module",
6
- "main": "./dist/index.js",
7
- "module": "./dist/index.js",
8
- "types": "./types/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "types": "./types/index.d.ts",
12
- "import": "./dist/index.js"
13
- },
14
- "./iife": "./dist/kintone-plugin-ide.iife.js",
15
- "./package.json": "./package.json"
16
- },
17
- "files": [
18
- "dist",
19
- "src",
20
- "types",
21
- "README.md",
22
- "LICENSE"
23
- ],
24
- "sideEffects": false,
25
- "scripts": {
26
- "build": "node build.mjs",
27
- "watch": "node build.mjs --watch",
28
- "test": "node test/smoke.mjs",
29
- "prepublishOnly": "npm run build && npm test"
30
- },
31
- "dependencies": {
32
- "fflate": "^0.8.2"
33
- },
34
- "devDependencies": {
35
- "esbuild": "^0.25.0"
36
- },
37
- "repository": {
38
- "type": "git",
39
- "url": "git+https://github.com/yusura0929/kintone-plugin-ide.git"
40
- },
41
- "homepage": "https://github.com/yusura0929/kintone-plugin-ide#readme",
42
- "bugs": {
43
- "url": "https://github.com/yusura0929/kintone-plugin-ide/issues"
44
- },
45
- "keywords": [
46
- "kintone",
47
- "kintone-plugin",
48
- "ide",
49
- "esbuild",
50
- "monaco"
51
- ],
52
- "license": "MIT",
53
- "engines": {
54
- "node": ">=22"
55
- },
56
- "publishConfig": {
57
- "access": "public"
58
- }
59
- }
1
+ {
2
+ "name": "kintone-plugin-ide",
3
+ "version": "0.3.1",
4
+ "description": "kintone のレコードを、そのままプラグインの開発環境(エディタ・ターミナル・ビルド・署名・インストール)にする",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./types/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./types/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./iife": "./dist/kintone-plugin-ide.iife.js",
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "src",
20
+ "types",
21
+ "README.md",
22
+ "LICENSE"
23
+ ],
24
+ "sideEffects": false,
25
+ "scripts": {
26
+ "build": "node build.mjs",
27
+ "watch": "node build.mjs --watch",
28
+ "test": "node test/smoke.mjs",
29
+ "prepublishOnly": "npm run build && npm test"
30
+ },
31
+ "dependencies": {
32
+ "fflate": "^0.8.2"
33
+ },
34
+ "devDependencies": {
35
+ "esbuild": "^0.25.0"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/yusura0929/kintone-plugin-ide.git"
40
+ },
41
+ "homepage": "https://github.com/yusura0929/kintone-plugin-ide#readme",
42
+ "bugs": {
43
+ "url": "https://github.com/yusura0929/kintone-plugin-ide/issues"
44
+ },
45
+ "keywords": [
46
+ "kintone",
47
+ "kintone-plugin",
48
+ "ide",
49
+ "esbuild",
50
+ "monaco"
51
+ ],
52
+ "license": "MIT",
53
+ "engines": {
54
+ "node": ">=22"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public"
58
+ }
59
+ }
@@ -1,87 +1,87 @@
1
- // manifest.json を読んで、必要なファイルをビルドし、contents.zip を作る
2
- import { zipSync } from 'fflate';
3
- import { loadEsbuild, loadValidator, loadCompiler } from '../deps.js';
4
- import { createTransformer } from './transformers.js';
5
- import { readPackageJson } from '../npm/registry.js';
6
- import { kb, toBytes } from '../util/bytes.js';
7
- import { normalize, isVendor } from '../util/path.js';
8
- import { vfsPlugin } from './vfs-plugin.js';
9
-
10
- export function sourceList(manifest) {
11
- const list = [];
12
- for (const [k, t] of [['desktop', 'js'], ['desktop', 'css'], ['mobile', 'js'], ['mobile', 'css'], ['config', 'js'], ['config', 'css']]) {
13
- for (const f of (manifest[k] && manifest[k][t]) || []) if (!/^https?:\/\//.test(f)) list.push(normalize(f));
14
- }
15
- if (manifest.config && manifest.config.html) list.push(normalize(manifest.config.html));
16
- list.push('manifest.json', normalize(manifest.icon));
17
- return [...new Set(list)];
18
- }
19
- // "js/desktop.js" → src/desktop.ts など / "css/desktop.css" → src/desktop.css
20
- export const entryCandidates = (out) => {
21
- const base = out.replace(/^(js|css)\//, '').replace(/\.(js|css)$/, '');
22
- return out.endsWith('.css') ? ['css', 'scss', 'sass', 'less'].map((e) => `src/${base}.${e}`) : ['ts', 'tsx', 'js', 'jsx'].map((e) => `src/${base}.${e}`);
23
- };
24
- const fmtMsg = (m) => (m.location ? `${m.location.file.replace(/^vfs:/, '')}:${m.location.line}:${m.location.column + 1} ` : '') + m.text;
25
-
26
- export async function validateManifest(manifest, outputs, log) {
27
- try {
28
- const validate = await loadValidator();
29
- const r = validate(manifest, {
30
- relativePath: (p) => outputs.has(normalize(p)),
31
- maxFileSize: (max, p) => !outputs.has(normalize(p)) || outputs.get(normalize(p)).length <= max,
32
- fileExists: (p) => outputs.has(normalize(p)),
33
- });
34
- for (const w of r.warnings || []) log.warn(`manifest.json: ${w.message}`);
35
- if (!r.valid) {
36
- for (const e of r.errors || []) log.error(`manifest.json${e.instancePath || ''}: ${e.message}`);
37
- throw new Error('manifest.json の検証に失敗しました');
38
- }
39
- log.ok('manifest.json の検証: OK');
40
- } catch (e) {
41
- if (/検証に失敗/.test(e.message)) throw e;
42
- log.warn(`manifest.json の検証をスキップしました (${e.message})`);
43
- }
44
- }
45
-
46
- export function readManifest(files) {
47
- if (!files.has('manifest.json')) throw new Error('manifest.json がありません');
48
- let manifest;
49
- try { manifest = JSON.parse(files.get('manifest.json')); } catch (e) { throw new Error('manifest.json がJSONとして読めません: ' + e.message); }
50
- for (const k of ['manifest_version', 'version', 'type', 'name', 'icon']) if (manifest[k] === undefined) throw new Error(`manifest.json に "${k}" がありません`);
51
- return manifest;
52
- }
53
-
54
- /**
55
- * npm のパッケージは esbuild がバンドルするので、js/*.js の中に入る。
56
- * node_modules/ そのものは contents.zip には入らない(manifest に書いたファイルだけが入る)。
57
- */
58
- export async function buildPlugin(files, log, { prod = false, vendor } = {}) {
59
- const manifest = readManifest(files);
60
- const outputs = new Map();
61
- const es = await loadEsbuild();
62
- const transform = createTransformer({ files, log, prod, load: loadCompiler, esbuild: es, deps: readPackageJson(files).dependencies });
63
- for (const out of sourceList(manifest)) {
64
- if (files.has(out) && !isVendor(out)) { outputs.set(out, toBytes(files.get(out))); continue; }
65
- const entry = (out.endsWith('.js') || out.endsWith('.css')) && entryCandidates(out).find((p) => files.has(p));
66
- if (!entry) throw new Error(`manifest.json の "${out}" がありません${/\.(js|css)$/.test(out) ? `(${entryCandidates(out).join(' / ')} も無し)` : ''}`);
67
- const t = performance.now();
68
- const r = await es.build({
69
- entryPoints: [entry], bundle: true, write: false, outfile: out,
70
- format: 'iife', target: 'es2020', charset: 'utf8', logLevel: 'silent',
71
- minify: prod, sourcemap: prod ? false : 'inline', legalComments: prod ? 'none' : 'inline',
72
- define: {
73
- 'process.env.NODE_ENV': JSON.stringify(prod ? 'production' : 'development'),
74
- __VUE_OPTIONS_API__: 'true', __VUE_PROD_DEVTOOLS__: 'false', __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'false',
75
- },
76
- plugins: [vfsPlugin(files, log, { vendor, transform })],
77
- }).catch((e) => e);
78
- for (const w of r.warnings || []) log.warn(fmtMsg(w));
79
- if (r.errors && r.errors.length) { r.errors.forEach((er) => log.error(fmtMsg(er))); throw new Error(`${entry} のビルドに失敗しました`); }
80
- const file = r.outputFiles.find((f) => f.path.endsWith(out.endsWith('.css') ? '.css' : '.js'));
81
- outputs.set(out, file.contents);
82
- log.ok(`${entry} → ${out} (${kb(file.contents.length)}, ${Math.round(performance.now() - t)} ms${prod ? ', 本番' : ''})`);
83
- }
84
- await validateManifest(manifest, outputs, log);
85
- const entries = {}; for (const [k, v] of outputs) entries[k] = v;
86
- return { manifest, contentsZip: zipSync(entries, { level: 9 }), outputs };
87
- }
1
+ // manifest.json を読んで、必要なファイルをビルドし、contents.zip を作る
2
+ import { zipSync } from 'fflate';
3
+ import { loadEsbuild, loadValidator, loadCompiler } from '../deps.js';
4
+ import { createTransformer } from './transformers.js';
5
+ import { readPackageJson } from '../npm/registry.js';
6
+ import { kb, toBytes } from '../util/bytes.js';
7
+ import { normalize, isVendor } from '../util/path.js';
8
+ import { vfsPlugin } from './vfs-plugin.js';
9
+
10
+ export function sourceList(manifest) {
11
+ const list = [];
12
+ for (const [k, t] of [['desktop', 'js'], ['desktop', 'css'], ['mobile', 'js'], ['mobile', 'css'], ['config', 'js'], ['config', 'css']]) {
13
+ for (const f of (manifest[k] && manifest[k][t]) || []) if (!/^https?:\/\//.test(f)) list.push(normalize(f));
14
+ }
15
+ if (manifest.config && manifest.config.html) list.push(normalize(manifest.config.html));
16
+ list.push('manifest.json', normalize(manifest.icon));
17
+ return [...new Set(list)];
18
+ }
19
+ // "js/desktop.js" → src/desktop.ts など / "css/desktop.css" → src/desktop.css
20
+ export const entryCandidates = (out) => {
21
+ const base = out.replace(/^(js|css)\//, '').replace(/\.(js|css)$/, '');
22
+ return out.endsWith('.css') ? ['css', 'scss', 'sass', 'less'].map((e) => `src/${base}.${e}`) : ['ts', 'tsx', 'js', 'jsx'].map((e) => `src/${base}.${e}`);
23
+ };
24
+ const fmtMsg = (m) => (m.location ? `${m.location.file.replace(/^vfs:/, '')}:${m.location.line}:${m.location.column + 1} ` : '') + m.text;
25
+
26
+ export async function validateManifest(manifest, outputs, log) {
27
+ try {
28
+ const validate = await loadValidator();
29
+ const r = validate(manifest, {
30
+ relativePath: (p) => outputs.has(normalize(p)),
31
+ maxFileSize: (max, p) => !outputs.has(normalize(p)) || outputs.get(normalize(p)).length <= max,
32
+ fileExists: (p) => outputs.has(normalize(p)),
33
+ });
34
+ for (const w of r.warnings || []) log.warn(`manifest.json: ${w.message}`);
35
+ if (!r.valid) {
36
+ for (const e of r.errors || []) log.error(`manifest.json${e.instancePath || ''}: ${e.message}`);
37
+ throw new Error('manifest.json の検証に失敗しました');
38
+ }
39
+ log.ok('manifest.json の検証: OK');
40
+ } catch (e) {
41
+ if (/検証に失敗/.test(e.message)) throw e;
42
+ log.warn(`manifest.json の検証をスキップしました (${e.message})`);
43
+ }
44
+ }
45
+
46
+ export function readManifest(files) {
47
+ if (!files.has('manifest.json')) throw new Error('manifest.json がありません');
48
+ let manifest;
49
+ try { manifest = JSON.parse(files.get('manifest.json')); } catch (e) { throw new Error('manifest.json がJSONとして読めません: ' + e.message); }
50
+ for (const k of ['manifest_version', 'version', 'type', 'name', 'icon']) if (manifest[k] === undefined) throw new Error(`manifest.json に "${k}" がありません`);
51
+ return manifest;
52
+ }
53
+
54
+ /**
55
+ * npm のパッケージは esbuild がバンドルするので、js/*.js の中に入る。
56
+ * node_modules/ そのものは contents.zip には入らない(manifest に書いたファイルだけが入る)。
57
+ */
58
+ export async function buildPlugin(files, log, { prod = false, vendor } = {}) {
59
+ const manifest = readManifest(files);
60
+ const outputs = new Map();
61
+ const es = await loadEsbuild();
62
+ const transform = createTransformer({ files, log, prod, load: loadCompiler, esbuild: es, deps: readPackageJson(files).dependencies });
63
+ for (const out of sourceList(manifest)) {
64
+ if (files.has(out) && !isVendor(out)) { outputs.set(out, toBytes(files.get(out))); continue; }
65
+ const entry = (out.endsWith('.js') || out.endsWith('.css')) && entryCandidates(out).find((p) => files.has(p));
66
+ if (!entry) throw new Error(`manifest.json の "${out}" がありません${/\.(js|css)$/.test(out) ? `(${entryCandidates(out).join(' / ')} も無し)` : ''}`);
67
+ const t = performance.now();
68
+ const r = await es.build({
69
+ entryPoints: [entry], bundle: true, write: false, outfile: out,
70
+ format: 'iife', target: 'es2020', charset: 'utf8', logLevel: 'silent',
71
+ minify: prod, sourcemap: prod ? false : 'inline', legalComments: prod ? 'none' : 'inline',
72
+ define: {
73
+ 'process.env.NODE_ENV': JSON.stringify(prod ? 'production' : 'development'),
74
+ __VUE_OPTIONS_API__: 'true', __VUE_PROD_DEVTOOLS__: 'false', __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'false',
75
+ },
76
+ plugins: [vfsPlugin(files, log, { vendor, transform })],
77
+ }).catch((e) => e);
78
+ for (const w of r.warnings || []) log.warn(fmtMsg(w));
79
+ if (r.errors && r.errors.length) { r.errors.forEach((er) => log.error(fmtMsg(er))); throw new Error(`${entry} のビルドに失敗しました`); }
80
+ const file = r.outputFiles.find((f) => f.path.endsWith(out.endsWith('.css') ? '.css' : '.js'));
81
+ outputs.set(out, file.contents);
82
+ log.ok(`${entry} → ${out} (${kb(file.contents.length)}, ${Math.round(performance.now() - t)} ms${prod ? ', 本番' : ''})`);
83
+ }
84
+ await validateManifest(manifest, outputs, log);
85
+ const entries = {}; for (const [k, v] of outputs) entries[k] = v;
86
+ return { manifest, contentsZip: zipSync(entries, { level: 9 }), outputs };
87
+ }