kintone-plugin-ide 0.3.0 → 0.4.0

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/package.json CHANGED
@@ -1,59 +1,62 @@
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.4.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
+ "esbuild-plugin-browser": "^0.1.0",
33
+ "fflate": "^0.8.2",
34
+ "kintone-plugin-web-signer": "^0.1.0"
35
+ },
36
+ "devDependencies": {
37
+ "esbuild": "^0.25.0"
38
+ },
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/yusura0929/kintone-plugin-ide.git",
42
+ "directory": "packages/ide"
43
+ },
44
+ "homepage": "https://github.com/yusura0929/kintone-plugin-ide/tree/main/packages/ide#readme",
45
+ "bugs": {
46
+ "url": "https://github.com/yusura0929/kintone-plugin-ide/issues"
47
+ },
48
+ "keywords": [
49
+ "kintone",
50
+ "kintone-plugin",
51
+ "ide",
52
+ "esbuild",
53
+ "monaco"
54
+ ],
55
+ "license": "MIT",
56
+ "engines": {
57
+ "node": ">=22"
58
+ },
59
+ "publishConfig": {
60
+ "access": "public"
61
+ }
62
+ }
@@ -1,87 +1,104 @@
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 { browserPlugin } from 'esbuild-plugin-browser';
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 { pkgDir, subFile } from '../npm/vendor.js';
9
+ import { idbGet, idbSet } from '../util/idb.js';
10
+ import { CONFIG } from '../config.js';
11
+ import { isBinary } from '../util/bytes.js';
12
+
13
+ export function sourceList(manifest) {
14
+ const list = [];
15
+ for (const [k, t] of [['desktop', 'js'], ['desktop', 'css'], ['mobile', 'js'], ['mobile', 'css'], ['config', 'js'], ['config', 'css']]) {
16
+ for (const f of (manifest[k] && manifest[k][t]) || []) if (!/^https?:\/\//.test(f)) list.push(normalize(f));
17
+ }
18
+ if (manifest.config && manifest.config.html) list.push(normalize(manifest.config.html));
19
+ list.push('manifest.json', normalize(manifest.icon));
20
+ return [...new Set(list)];
21
+ }
22
+ // "js/desktop.js" → src/desktop.ts など / "css/desktop.css" → src/desktop.css
23
+ export const entryCandidates = (out) => {
24
+ const base = out.replace(/^(js|css)\//, '').replace(/\.(js|css)$/, '');
25
+ return out.endsWith('.css') ? ['css', 'scss', 'sass', 'less'].map((e) => `src/${base}.${e}`) : ['ts', 'tsx', 'js', 'jsx'].map((e) => `src/${base}.${e}`);
26
+ };
27
+ const fmtMsg = (m) => (m.location ? `${m.location.file.replace(/^vfs:/, '')}:${m.location.line}:${m.location.column + 1} ` : '') + m.text;
28
+
29
+ export async function validateManifest(manifest, outputs, log) {
30
+ try {
31
+ const validate = await loadValidator();
32
+ const r = validate(manifest, {
33
+ relativePath: (p) => outputs.has(normalize(p)),
34
+ maxFileSize: (max, p) => !outputs.has(normalize(p)) || outputs.get(normalize(p)).length <= max,
35
+ fileExists: (p) => outputs.has(normalize(p)),
36
+ });
37
+ for (const w of r.warnings || []) log.warn(`manifest.json: ${w.message}`);
38
+ if (!r.valid) {
39
+ for (const e of r.errors || []) log.error(`manifest.json${e.instancePath || ''}: ${e.message}`);
40
+ throw new Error('manifest.json の検証に失敗しました');
41
+ }
42
+ log.ok('manifest.json の検証: OK');
43
+ } catch (e) {
44
+ if (/検証に失敗/.test(e.message)) throw e;
45
+ log.warn(`manifest.json の検証をスキップしました (${e.message})`);
46
+ }
47
+ }
48
+
49
+ export function readManifest(files) {
50
+ if (!files.has('manifest.json')) throw new Error('manifest.json がありません');
51
+ let manifest;
52
+ try { manifest = JSON.parse(files.get('manifest.json')); } catch (e) { throw new Error('manifest.json がJSONとして読めません: ' + e.message); }
53
+ for (const k of ['manifest_version', 'version', 'type', 'name', 'icon']) if (manifest[k] === undefined) throw new Error(`manifest.json に "${k}" がありません`);
54
+ return manifest;
55
+ }
56
+
57
+ /**
58
+ * npm のパッケージは esbuild がバンドルするので、js/*.js の中に入る。
59
+ * node_modules/ そのものは contents.zip には入らない(manifest に書いたファイルだけが入る)。
60
+ */
61
+ export async function buildPlugin(files, log, { prod = false, vendor } = {}) {
62
+ const manifest = readManifest(files);
63
+ const outputs = new Map();
64
+ const es = await loadEsbuild();
65
+ // IDE のファイルは文字列(バイナリは "base64:...")。プラグインには Uint8Array で見せる
66
+ const source = { has: (p) => files.has(p), get: (p) => { const t = files.get(p); return t !== undefined && isBinary(t) ? toBytes(t) : t; } };
67
+ // npm のパッケージは node_modules/ に置いたものを使う。無ければ取ってきて置く(vendor)
68
+ const resolvePackage = async (name, sub) => {
69
+ const target = sub ? subFile(name, sub) : `${pkgDir(name)}index.mjs`;
70
+ if (files.has(target)) return target;
71
+ return vendor ? vendor(name, sub) : null;
72
+ };
73
+ const plugin = () => browserPlugin({
74
+ files: source, esbuild: es, prod, cdn: CONFIG.CDN.npm, resolvePackage,
75
+ dependencies: readPackageJson(files).dependencies,
76
+ transform: { load: loadCompiler },
77
+ cache: { get: idbGet, set: idbSet },
78
+ log: { info: log.info, warn: (t) => log.warn(/package\.json にありません/.test(t) ? `${t}。npm install で node_modules に入ります` : t) },
79
+ });
80
+ for (const out of sourceList(manifest)) {
81
+ if (files.has(out) && !isVendor(out)) { outputs.set(out, toBytes(files.get(out))); continue; }
82
+ const entry = (out.endsWith('.js') || out.endsWith('.css')) && entryCandidates(out).find((p) => files.has(p));
83
+ if (!entry) throw new Error(`manifest.json の "${out}" がありません${/\.(js|css)$/.test(out) ? `(${entryCandidates(out).join(' / ')} も無し)` : ''}`);
84
+ const t = performance.now();
85
+ const r = await es.build({
86
+ entryPoints: [entry], bundle: true, write: false, outfile: out,
87
+ format: 'iife', target: 'es2020', charset: 'utf8', logLevel: 'silent',
88
+ minify: prod, sourcemap: prod ? false : 'inline', legalComments: prod ? 'none' : 'inline',
89
+ define: {
90
+ 'process.env.NODE_ENV': JSON.stringify(prod ? 'production' : 'development'),
91
+ __VUE_OPTIONS_API__: 'true', __VUE_PROD_DEVTOOLS__: 'false', __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'false',
92
+ },
93
+ plugins: [plugin()],
94
+ }).catch((e) => e);
95
+ for (const w of r.warnings || []) log.warn(fmtMsg(w));
96
+ if (r.errors && r.errors.length) { r.errors.forEach((er) => log.error(fmtMsg(er))); throw new Error(`${entry} のビルドに失敗しました`); }
97
+ const file = r.outputFiles.find((f) => f.path.endsWith(out.endsWith('.css') ? '.css' : '.js'));
98
+ outputs.set(out, file.contents);
99
+ log.ok(`${entry} → ${out} (${kb(file.contents.length)}, ${Math.round(performance.now() - t)} ms${prod ? ', 本番' : ''})`);
100
+ }
101
+ await validateManifest(manifest, outputs, log);
102
+ const entries = {}; for (const [k, v] of outputs) entries[k] = v;
103
+ return { manifest, contentsZip: zipSync(entries, { level: 9 }), outputs };
104
+ }
package/src/config.js CHANGED
@@ -1,58 +1,56 @@
1
- // 既定値。環境ごとの値は setup({ ... }) で渡す(このファイルは書き換えない)
2
- export const CONFIG = {
3
- FIELDS: {
4
- source: 'source_zip', // 添付ファイル: ソース一式の zip(node_modules は入れない)
5
- key: 'private_key', zip: 'plugin_zip', id: 'plugin_id', testApp: 'test_app',
6
- // 前の版(サブテーブルにソースを展開していた頃)のフィールド。あれば最初の1回だけ読んで zip に移す
7
- legacy: { files: 'files', path: 'path', content: 'content' },
8
- },
9
- INSTALL_HOSTS: [], // インストールしてよい環境(setup の installHosts で渡す)。空ならインストールしない
10
- THEME: 'vitesse-dark',
11
- CDN: {
12
- monaco: 'https://esm.sh/modern-monaco@0.3.8', // 0.4 系は言語サービスが動かない(kintone 上で確認)
13
- trees: 'https://esm.sh/@pierre/trees@1.0.0',
14
- xterm: 'https://esm.sh/@xterm/xterm@5.5.0',
15
- xtermCss: 'https://cdn.jsdelivr.net/npm/@xterm/xterm@5.5.0/css/xterm.css',
16
- xtermFit: 'https://esm.sh/@xterm/addon-fit@0.10.0',
17
- xtermReadline: 'https://esm.sh/xterm-readline@1.1.2',
18
- esbuild: 'https://cdn.jsdelivr.net/npm/esbuild-wasm@0.28.2/esm/browser.min.js',
19
- esbuildWasm: 'https://cdn.jsdelivr.net/npm/esbuild-wasm@0.28.2/esbuild.wasm',
20
- validator: 'https://esm.sh/@kintone/plugin-manifest-validator@12.0.1',
21
- prettier: 'https://esm.sh/prettier@3/standalone',
22
- prettierPlugins: ['babel', 'estree', 'typescript', 'postcss', 'html', 'markdown', 'yaml'].map((p) => `https://esm.sh/prettier@3/plugins/${p}`),
23
- // kintone の型(@kintone/dts-gen)。tsconfig.json の types に URL のまま書ける
24
- kintoneDts: 'https://cdn.jsdelivr.net/npm/@kintone/dts-gen@10.0.0/kintone.d.ts',
25
- // .svelte / .vue のコンパイラは package.json のバージョン(:range)に合わせる
26
- compilers: {
27
- svelte: 'https://esm.sh/svelte@:range/compiler?target=es2020&bundle',
28
- vue: 'https://esm.sh/@vue/compiler-sfc@:range?target=es2020&bundle',
29
- sass: 'https://esm.sh/sass@1?target=es2020&bundle',
30
- less: 'https://esm.sh/less@4?target=es2020&bundle',
31
- yaml: 'https://esm.sh/js-yaml@4?target=es2020&bundle',
32
- },
33
- npm: 'https://esm.sh',
34
- registry: 'https://registry.npmjs.org',
35
- },
36
- };
37
- export const F = CONFIG.FIELDS;
38
- export const BINARY_PREFIX = 'base64:';
39
- export const SETTINGS_KEY = 'kintone-plugin-ide:settings';
40
- export const NODE_MODULES = 'node_modules/';
41
- // 状態をモジュールで共有するランタイム。サブパスごとに丸ごと抱え込むと二重に入って壊れるので、
42
- // esm.sh の分割されたモジュールをそのまま読んで esbuild にまとめさせる(node_modules には印だけ置く)
43
- export const SHARED_RUNTIMES = /^(svelte|vue|@vue\/.+|react|react-dom|preact|solid-js|lit|@lit\/.+)$/;
44
-
45
- // setup() の引数を CONFIG に重ねる。オブジェクトは差し替えずに中身を書き換える
46
- // (ほかのモジュールが CONFIG.FIELDS などを直接つかんでいるため)
47
- const isObj = (v) => v && typeof v === 'object' && !Array.isArray(v);
48
- function merge(target, src) {
49
- for (const [k, v] of Object.entries(src)) {
50
- if (v === undefined) continue;
51
- if (isObj(v) && isObj(target[k])) merge(target[k], v);
52
- else target[k] = v;
53
- }
54
- }
55
- export function configure({ installHosts, fields, theme, cdn } = {}) {
56
- merge(CONFIG, { INSTALL_HOSTS: installHosts, FIELDS: fields, THEME: theme, CDN: cdn });
57
- return CONFIG;
58
- }
1
+ // 既定値。環境ごとの値は setup({ ... }) で渡す(このファイルは書き換えない)
2
+ export const CONFIG = {
3
+ FIELDS: {
4
+ source: 'source_zip', // 添付ファイル: ソース一式の zip(node_modules は入れない)
5
+ key: 'private_key', zip: 'plugin_zip', id: 'plugin_id', testApp: 'test_app',
6
+ // 前の版(サブテーブルにソースを展開していた頃)のフィールド。あれば最初の1回だけ読んで zip に移す
7
+ legacy: { files: 'files', path: 'path', content: 'content' },
8
+ },
9
+ INSTALL_HOSTS: [], // インストールしてよい環境(setup の installHosts で渡す)。空ならインストールしない
10
+ THEME: 'vitesse-dark',
11
+ CDN: {
12
+ monaco: 'https://esm.sh/modern-monaco@0.3.8', // 0.4 系は言語サービスが動かない(kintone 上で確認)
13
+ trees: 'https://esm.sh/@pierre/trees@1.0.0',
14
+ xterm: 'https://esm.sh/@xterm/xterm@5.5.0',
15
+ xtermCss: 'https://cdn.jsdelivr.net/npm/@xterm/xterm@5.5.0/css/xterm.css',
16
+ xtermFit: 'https://esm.sh/@xterm/addon-fit@0.10.0',
17
+ xtermReadline: 'https://esm.sh/xterm-readline@1.1.2',
18
+ esbuild: 'https://cdn.jsdelivr.net/npm/esbuild-wasm@0.28.2/esm/browser.min.js',
19
+ esbuildWasm: 'https://cdn.jsdelivr.net/npm/esbuild-wasm@0.28.2/esbuild.wasm',
20
+ validator: 'https://esm.sh/@kintone/plugin-manifest-validator@12.0.1',
21
+ prettier: 'https://esm.sh/prettier@3/standalone',
22
+ prettierPlugins: ['babel', 'estree', 'typescript', 'postcss', 'html', 'markdown', 'yaml'].map((p) => `https://esm.sh/prettier@3/plugins/${p}`),
23
+ // kintone の型(@kintone/dts-gen)。tsconfig.json の types に URL のまま書ける
24
+ kintoneDts: 'https://cdn.jsdelivr.net/npm/@kintone/dts-gen@10.0.0/kintone.d.ts',
25
+ // .svelte / .vue のコンパイラは package.json のバージョン(:range)に合わせる
26
+ compilers: {
27
+ svelte: 'https://esm.sh/svelte@:range/compiler?target=es2020&bundle',
28
+ vue: 'https://esm.sh/@vue/compiler-sfc@:range?target=es2020&bundle',
29
+ sass: 'https://esm.sh/sass@1?target=es2020&bundle',
30
+ less: 'https://esm.sh/less@4?target=es2020&bundle',
31
+ yaml: 'https://esm.sh/js-yaml@4?target=es2020&bundle',
32
+ },
33
+ npm: 'https://esm.sh',
34
+ registry: 'https://registry.npmjs.org',
35
+ },
36
+ };
37
+ export const F = CONFIG.FIELDS;
38
+ export const BINARY_PREFIX = 'base64:';
39
+ export const SETTINGS_KEY = 'kintone-plugin-ide:settings';
40
+ export const NODE_MODULES = 'node_modules/';
41
+ export { SHARED_RUNTIMES } from 'esbuild-plugin-browser';
42
+
43
+ // setup() の引数を CONFIG に重ねる。オブジェクトは差し替えずに中身を書き換える
44
+ // (ほかのモジュールが CONFIG.FIELDS などを直接つかんでいるため)
45
+ const isObj = (v) => v && typeof v === 'object' && !Array.isArray(v);
46
+ function merge(target, src) {
47
+ for (const [k, v] of Object.entries(src)) {
48
+ if (v === undefined) continue;
49
+ if (isObj(v) && isObj(target[k])) merge(target[k], v);
50
+ else target[k] = v;
51
+ }
52
+ }
53
+ export function configure({ installHosts, fields, theme, cdn } = {}) {
54
+ merge(CONFIG, { INSTALL_HOSTS: installHosts, FIELDS: fields, THEME: theme, CDN: cdn });
55
+ return CONFIG;
56
+ }
package/src/deps.js CHANGED
@@ -1,41 +1,41 @@
1
- // 外部ライブラリの読み込みは全部ここに集める。
2
- // 自分のプロジェクトでバンドルするときは、ここの import(CONFIG.CDN.xxx) を
3
- // import('modern-monaco') のような素の指定に変えれば、npm のパッケージがそのまま入る。
4
- import { CONFIG } from './config.js';
5
- import { workspaceFS } from './ide/workspace-fs.js';
6
-
7
- const once = (fn) => { let p; return () => (p ??= fn()); };
8
-
9
- export const loadTrees = once(() => import(CONFIG.CDN.trees));
10
- export const loadValidator = once(() => import(CONFIG.CDN.validator).then((m) => m.default || m));
11
- export const loadXterm = once(async () => {
12
- const [{ Terminal }, { FitAddon }, { Readline }] = await Promise.all([
13
- import(CONFIG.CDN.xterm), import(CONFIG.CDN.xtermFit), import(CONFIG.CDN.xtermReadline),
14
- ]);
15
- return { Terminal, FitAddon, Readline, css: CONFIG.CDN.xtermCss };
16
- });
17
- export const loadPrettier = once(async () => {
18
- const [prettier, ...plugins] = await Promise.all([import(CONFIG.CDN.prettier), ...CONFIG.CDN.prettierPlugins.map((u) => import(u))]);
19
- return { prettier, plugins: plugins.map((p) => p.default || p) };
20
- });
21
- export const loadEsbuild = once(async () => {
22
- const es = await import(CONFIG.CDN.esbuild);
23
- try { await es.initialize({ wasmURL: CONFIG.CDN.esbuildWasm }); } catch (e) {
24
- if (!/more than once/.test(e.message)) throw e; // 同じページで2回目に開いた時は初期化済み
25
- }
26
- return es;
27
- });
28
- // modern-monaco はページに1回しか init できないので、ファイルシステムは差し替えのきく1つを渡す
29
- export const loadMonaco = once(async () => {
30
- const m = await import(CONFIG.CDN.monaco);
31
- const workspace = new m.Workspace({ name: 'kintone-plugin-ide', customFS: workspaceFS });
32
- return m.init({ defaultTheme: CONFIG.THEME, workspace });
33
- });
34
-
35
- // .svelte / .vue / .scss / .less / .yaml のコンパイラ
36
- const compilers = new Map();
37
- export function loadCompiler(name, range = '') {
38
- const url = CONFIG.CDN.compilers[name].replace(':range', range);
39
- if (!compilers.has(url)) compilers.set(url, import(url).catch((e) => { compilers.delete(url); throw new Error(`${name} のコンパイラを読めませんでした: ${e.message}`); }));
40
- return compilers.get(url);
41
- }
1
+ // 外部ライブラリの読み込みは全部ここに集める。
2
+ // 自分のプロジェクトでバンドルするときは、ここの import(CONFIG.CDN.xxx) を
3
+ // import('modern-monaco') のような素の指定に変えれば、npm のパッケージがそのまま入る。
4
+ import { CONFIG } from './config.js';
5
+ import { workspaceFS } from './ide/workspace-fs.js';
6
+
7
+ const once = (fn) => { let p; return () => (p ??= fn()); };
8
+
9
+ export const loadTrees = once(() => import(CONFIG.CDN.trees));
10
+ export const loadValidator = once(() => import(CONFIG.CDN.validator).then((m) => m.default || m));
11
+ export const loadXterm = once(async () => {
12
+ const [{ Terminal }, { FitAddon }, { Readline }] = await Promise.all([
13
+ import(CONFIG.CDN.xterm), import(CONFIG.CDN.xtermFit), import(CONFIG.CDN.xtermReadline),
14
+ ]);
15
+ return { Terminal, FitAddon, Readline, css: CONFIG.CDN.xtermCss };
16
+ });
17
+ export const loadPrettier = once(async () => {
18
+ const [prettier, ...plugins] = await Promise.all([import(CONFIG.CDN.prettier), ...CONFIG.CDN.prettierPlugins.map((u) => import(u))]);
19
+ return { prettier, plugins: plugins.map((p) => p.default || p) };
20
+ });
21
+ export const loadEsbuild = once(async () => {
22
+ const es = await import(CONFIG.CDN.esbuild);
23
+ try { await es.initialize({ wasmURL: CONFIG.CDN.esbuildWasm }); } catch (e) {
24
+ if (!/more than once/.test(e.message)) throw e; // 同じページで2回目に開いた時は初期化済み
25
+ }
26
+ return es;
27
+ });
28
+ // modern-monaco はページに1回しか init できないので、ファイルシステムは差し替えのきく1つを渡す
29
+ export const loadMonaco = once(async () => {
30
+ const m = await import(CONFIG.CDN.monaco);
31
+ const workspace = new m.Workspace({ name: 'kintone-plugin-ide', customFS: workspaceFS });
32
+ return m.init({ defaultTheme: CONFIG.THEME, workspace });
33
+ });
34
+
35
+ // .svelte / .vue / .scss / .less / .yaml のコンパイラ
36
+ const compilers = new Map();
37
+ export function loadCompiler(name, range = '') {
38
+ const url = CONFIG.CDN.compilers[name].replace(':range', range);
39
+ if (!compilers.has(url)) compilers.set(url, import(url).catch((e) => { compilers.delete(url); throw new Error(`${name} のコンパイラを読めませんでした: ${e.message}`); }));
40
+ return compilers.get(url);
41
+ }