kintone-plugin-ide 0.3.1 → 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/README.md +5 -3
- package/dist/index.js +41 -315
- package/dist/kintone-plugin-ide.iife.js +442 -316
- package/package.json +7 -4
- package/src/build/build.js +21 -4
- package/src/config.js +1 -3
- package/src/ide/actions/release.js +1 -1
- package/src/ide/actions/zip.js +1 -1
- package/src/index.js +3 -2
- package/src/npm/vendor.js +3 -3
- package/src/build/http-plugin.js +0 -32
- package/src/build/transformers.js +0 -168
- package/src/build/vfs-plugin.js +0 -60
- package/src/packer/packer.js +0 -50
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* kintone-plugin-ide v0.
|
|
1
|
+
/* kintone-plugin-ide v0.4.0 (src/ からビルド) */
|
|
2
2
|
var KintonePluginIDE = (() => {
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -25,6 +25,7 @@ var KintonePluginIDE = (() => {
|
|
|
25
25
|
__export(index_exports, {
|
|
26
26
|
CONFIG: () => CONFIG,
|
|
27
27
|
addToTestApp: () => addToTestApp,
|
|
28
|
+
browserPlugin: () => browserPlugin,
|
|
28
29
|
buildPlugin: () => buildPlugin,
|
|
29
30
|
configure: () => configure,
|
|
30
31
|
deployApp: () => deployApp,
|
|
@@ -33,12 +34,314 @@ var KintonePluginIDE = (() => {
|
|
|
33
34
|
install: () => install,
|
|
34
35
|
openIDE: () => openIDE,
|
|
35
36
|
pack: () => pack,
|
|
37
|
+
packFiles: () => packFiles,
|
|
38
|
+
publicKeyFromPpk: () => publicKeyFromPpk,
|
|
36
39
|
readManifest: () => readManifest,
|
|
37
40
|
setup: () => setup,
|
|
38
41
|
sourceList: () => sourceList,
|
|
39
42
|
unpack: () => unpack
|
|
40
43
|
});
|
|
41
44
|
|
|
45
|
+
// ../esbuild-plugin-browser/src/path.js
|
|
46
|
+
var dirname = (p) => p.split("/").slice(0, -1).join("/");
|
|
47
|
+
var normalize = (p) => {
|
|
48
|
+
const out = [];
|
|
49
|
+
for (const s of String(p).split("/")) {
|
|
50
|
+
if (!s || s === ".") continue;
|
|
51
|
+
if (s === "..") out.pop();
|
|
52
|
+
else out.push(s);
|
|
53
|
+
}
|
|
54
|
+
return out.join("/");
|
|
55
|
+
};
|
|
56
|
+
var ext = (p) => p.split(".").pop().toLowerCase();
|
|
57
|
+
|
|
58
|
+
// ../esbuild-plugin-browser/src/npm.js
|
|
59
|
+
function parseSpecifier(spec) {
|
|
60
|
+
const parts = spec.split("/");
|
|
61
|
+
const n = spec.startsWith("@") ? 2 : 1;
|
|
62
|
+
return { name: parts.slice(0, n).join("/"), sub: parts.length > n ? "/" + parts.slice(n).join("/") : "" };
|
|
63
|
+
}
|
|
64
|
+
var SHARED_RUNTIMES = /^(svelte|vue|@vue\/.+|react|react-dom|preact|solid-js|lit|@lit\/.+)$/;
|
|
65
|
+
function esmShUrl(cdn, name, range, sub = "", { shared = false, target = "es2020" } = {}) {
|
|
66
|
+
const base = `${cdn}/${name}${range ? "@" + range : ""}${sub}`;
|
|
67
|
+
if (/\.css$/.test(sub)) return base;
|
|
68
|
+
return `${base}?target=${target}${shared ? "" : "&bundle"}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ../esbuild-plugin-browser/src/http.js
|
|
72
|
+
var immutable = (u) => /@\d+\.\d+\.\d+(-[\w.]+)?\//.test(u) && !/[\^~*]/.test(decodeURIComponent(u));
|
|
73
|
+
function httpPlugin({ cache, log, fetch: f = globalThis.fetch.bind(globalThis) } = {}) {
|
|
74
|
+
const memo = /* @__PURE__ */ new Map();
|
|
75
|
+
return {
|
|
76
|
+
name: "http",
|
|
77
|
+
setup(b) {
|
|
78
|
+
b.onResolve({ filter: /^https?:\/\// }, (a) => ({ path: a.path, namespace: "http" }));
|
|
79
|
+
b.onResolve({ filter: /.*/, namespace: "http" }, (a) => ({ path: new URL(a.path, a.importer).href, namespace: "http" }));
|
|
80
|
+
b.onLoad({ filter: /.*/, namespace: "http" }, async (a) => {
|
|
81
|
+
if (!memo.has(a.path)) {
|
|
82
|
+
const keep = cache && immutable(a.path);
|
|
83
|
+
let text = keep ? await cache.get(`http:${a.path}`) : void 0;
|
|
84
|
+
if (text === void 0 || text === null) {
|
|
85
|
+
log?.info?.(`取得: ${a.path}`);
|
|
86
|
+
const res = await f(a.path);
|
|
87
|
+
if (!res.ok) throw new Error(`${res.status} ${a.path}`);
|
|
88
|
+
text = await res.text();
|
|
89
|
+
if (keep) await cache.set(`http:${a.path}`, text);
|
|
90
|
+
}
|
|
91
|
+
memo.set(a.path, text);
|
|
92
|
+
}
|
|
93
|
+
return { contents: memo.get(a.path), loader: /\.css(\?|$)/.test(a.path) ? "css" : "js" };
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// ../esbuild-plugin-browser/src/transformers.js
|
|
100
|
+
var DEFAULT_COMPILERS = {
|
|
101
|
+
svelte: "https://esm.sh/svelte@:range/compiler?target=es2020&bundle",
|
|
102
|
+
vue: "https://esm.sh/@vue/compiler-sfc@:range?target=es2020&bundle",
|
|
103
|
+
sass: "https://esm.sh/sass@1?target=es2020&bundle",
|
|
104
|
+
less: "https://esm.sh/less@4?target=es2020&bundle",
|
|
105
|
+
yaml: "https://esm.sh/js-yaml@4?target=es2020&bundle"
|
|
106
|
+
};
|
|
107
|
+
var loaded = /* @__PURE__ */ new Map();
|
|
108
|
+
function compilerLoader(templates = DEFAULT_COMPILERS) {
|
|
109
|
+
return (name, range = "") => {
|
|
110
|
+
const url = (templates[name] || DEFAULT_COMPILERS[name]).replace(":range", range);
|
|
111
|
+
if (!loaded.has(url)) loaded.set(url, import(
|
|
112
|
+
/* @vite-ignore */
|
|
113
|
+
url
|
|
114
|
+
).catch((e) => {
|
|
115
|
+
loaded.delete(url);
|
|
116
|
+
throw new Error(`${name} のコンパイラを読めませんでした: ${e.message}`);
|
|
117
|
+
}));
|
|
118
|
+
return loaded.get(url);
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
var TRANSFORM_EXT = /\.(svelte|svelte\.[jt]s|vue|s[ac]ss|less|ya?ml)$/;
|
|
122
|
+
var fail = (path, message, loc) => ({ errors: [{ text: message, location: loc ? { file: path, line: loc.line, column: loc.column ?? 0 } : { file: path } }] });
|
|
123
|
+
var injectCss = (css, id) => css.trim() ? `
|
|
124
|
+
;(()=>{if(typeof document==='undefined'||document.getElementById(${JSON.stringify(id)}))return;const s=document.createElement('style');s.id=${JSON.stringify(id)};s.textContent=${JSON.stringify(css)};document.head.appendChild(s)})();
|
|
125
|
+
` : "";
|
|
126
|
+
var hashId = (s) => {
|
|
127
|
+
let h = 5381;
|
|
128
|
+
for (let i = 0; i < s.length; i++) h = (h << 5) + h + s.charCodeAt(i) >>> 0;
|
|
129
|
+
return h.toString(36);
|
|
130
|
+
};
|
|
131
|
+
function createTransformer({ files, log = {}, prod = false, load = compilerLoader(), esbuild, deps = {} }) {
|
|
132
|
+
const textOf = (p) => {
|
|
133
|
+
const v = files.get(p);
|
|
134
|
+
return typeof v === "string" ? v : new TextDecoder().decode(v);
|
|
135
|
+
};
|
|
136
|
+
const need = (name) => {
|
|
137
|
+
if (!deps[name]) throw new Error(`${name} が package.json にありません。npm install ${name} してください(ランタイムとコンパイラのバージョンをそろえるため)`);
|
|
138
|
+
return deps[name];
|
|
139
|
+
};
|
|
140
|
+
async function compileSass(path, text) {
|
|
141
|
+
const sass = await load("sass");
|
|
142
|
+
const toUrl = (p) => new URL(`file:///${p}`);
|
|
143
|
+
const candidates = (p) => {
|
|
144
|
+
const d = dirname(p), b = p.split("/").pop();
|
|
145
|
+
const bases = /\.(s[ac]ss|css)$/.test(b) ? [p] : [`${p}.scss`, `${p}.sass`, `${p}.css`, `${d ? d + "/" : ""}_${b}.scss`, `${d ? d + "/" : ""}_${b}.sass`, `${p}/index.scss`, `${p}/_index.scss`];
|
|
146
|
+
return bases.map(normalize);
|
|
147
|
+
};
|
|
148
|
+
const importer = {
|
|
149
|
+
canonicalize(url, ctx) {
|
|
150
|
+
const base = ctx && ctx.containingUrl ? ctx.containingUrl.pathname.slice(1) : path;
|
|
151
|
+
const raw = url.startsWith("file:///") ? url.slice(8) : normalize(`${dirname(base)}/${url}`);
|
|
152
|
+
const hit = candidates(raw).find((c) => files.has(c));
|
|
153
|
+
return hit ? toUrl(hit) : null;
|
|
154
|
+
},
|
|
155
|
+
load(u) {
|
|
156
|
+
const p = decodeURIComponent(u.pathname.slice(1));
|
|
157
|
+
return { contents: textOf(p), syntax: p.endsWith(".sass") ? "indented" : p.endsWith(".css") ? "css" : "scss" };
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
try {
|
|
161
|
+
const r = sass.compileString(text, { url: toUrl(path), syntax: path.endsWith(".sass") ? "indented" : "scss", importers: [importer], style: prod ? "compressed" : "expanded", silenceDeprecations: ["import"] });
|
|
162
|
+
return r.css;
|
|
163
|
+
} catch (e) {
|
|
164
|
+
const s = e.span;
|
|
165
|
+
throw Object.assign(new Error(e.sassMessage || e.message), { loc: s ? { line: s.start.line + 1, column: s.start.column } : null, file: s && s.url ? s.url.pathname.slice(1) : path });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async function compileLess(path, text) {
|
|
169
|
+
const mod = await load("less");
|
|
170
|
+
const less = mod.default || mod;
|
|
171
|
+
const vfs = {
|
|
172
|
+
install(lessObj, pm) {
|
|
173
|
+
class VfsFileManager extends lessObj.FileManager {
|
|
174
|
+
supports() {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
supportsSync() {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
loadFile(filename, currentDirectory) {
|
|
181
|
+
const base = normalize(`${currentDirectory || dirname(path)}/${filename}`);
|
|
182
|
+
const hit = [base, `${base}.less`, `${base}.css`].find((c) => files.has(c));
|
|
183
|
+
return hit ? Promise.resolve({ contents: textOf(hit), filename: hit }) : Promise.reject({ type: "File", message: `ファイルが見つかりません: ${filename}` });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
pm.addFileManager(new VfsFileManager());
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
try {
|
|
190
|
+
return (await less.render(text, { filename: path, plugins: [vfs], compress: prod })).css;
|
|
191
|
+
} catch (e) {
|
|
192
|
+
throw Object.assign(new Error(e.message), { loc: e.line ? { line: e.line, column: e.column || 0 } : null, file: e.filename || path });
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async function compileSvelte(path, text) {
|
|
196
|
+
const svelte = await load("svelte", need("svelte"));
|
|
197
|
+
const warn = (w) => log.warn?.(`${path}${w.start ? `:${w.start.line}:${w.start.column + 1}` : ""} ${w.message}`);
|
|
198
|
+
try {
|
|
199
|
+
if (/\.svelte\.[jt]s$/.test(path)) {
|
|
200
|
+
const js = path.endsWith(".ts") ? (await esbuild.transform(text, { loader: "ts", sourcefile: path })).code : text;
|
|
201
|
+
const r2 = svelte.compileModule(js, { filename: path, generate: "client", dev: !prod });
|
|
202
|
+
r2.warnings.forEach(warn);
|
|
203
|
+
return { contents: r2.js.code, loader: "js" };
|
|
204
|
+
}
|
|
205
|
+
const r = svelte.compile(text, { filename: path, generate: "client", dev: !prod, css: "injected" });
|
|
206
|
+
r.warnings.forEach(warn);
|
|
207
|
+
return { contents: r.js.code, loader: "js" };
|
|
208
|
+
} catch (e) {
|
|
209
|
+
throw Object.assign(new Error(e.message), { loc: e.start ? { line: e.start.line, column: e.start.column } : null });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async function compileVue(path, text) {
|
|
213
|
+
const sfc = await load("vue", need("vue"));
|
|
214
|
+
const { descriptor, errors } = sfc.parse(text, { filename: path });
|
|
215
|
+
if (errors.length) {
|
|
216
|
+
const e = errors[0];
|
|
217
|
+
throw Object.assign(new Error(e.message), { loc: e.loc ? { line: e.loc.start.line, column: e.loc.start.column - 1 } : null });
|
|
218
|
+
}
|
|
219
|
+
const id = hashId(path);
|
|
220
|
+
const scoped = descriptor.styles.some((s) => s.scoped);
|
|
221
|
+
let code = "", lang = "js";
|
|
222
|
+
if (descriptor.script || descriptor.scriptSetup) {
|
|
223
|
+
const s = sfc.compileScript(descriptor, { id, inlineTemplate: true, isProd: prod, genDefaultAs: "__sfc__", templateOptions: { compilerOptions: { scopeId: scoped ? `data-v-${id}` : void 0 } } });
|
|
224
|
+
code = s.content;
|
|
225
|
+
lang = /tsx?/.test((descriptor.scriptSetup || descriptor.script).lang || "") ? "ts" : "js";
|
|
226
|
+
} else code = "const __sfc__ = {};";
|
|
227
|
+
if (descriptor.template && !descriptor.scriptSetup) {
|
|
228
|
+
const t = sfc.compileTemplate({ source: descriptor.template.content, filename: path, id, scoped, isProd: prod, compilerOptions: { scopeId: scoped ? `data-v-${id}` : void 0 } });
|
|
229
|
+
if (t.errors.length) throw new Error(String(t.errors[0].message || t.errors[0]));
|
|
230
|
+
code += `
|
|
231
|
+
${t.code.replace(/\nexport (function|const) (render|ssrRender)/, "\n$1 $2")}
|
|
232
|
+
__sfc__.render = render;`;
|
|
233
|
+
}
|
|
234
|
+
if (scoped) code += `
|
|
235
|
+
__sfc__.__scopeId = "data-v-${id}";`;
|
|
236
|
+
let css = "";
|
|
237
|
+
for (const st of descriptor.styles) {
|
|
238
|
+
let source = st.content;
|
|
239
|
+
if (/^s[ac]ss$/.test(st.lang || "")) source = await compileSass(`${path}.${st.lang}`, source);
|
|
240
|
+
else if (st.lang === "less") source = await compileLess(`${path}.less`, source);
|
|
241
|
+
const r = sfc.compileStyle({ source, filename: path, id: `data-v-${id}`, scoped: st.scoped, isProd: prod });
|
|
242
|
+
if (r.errors.length) throw new Error(String(r.errors[0].message || r.errors[0]));
|
|
243
|
+
css += r.code + "\n";
|
|
244
|
+
}
|
|
245
|
+
code += injectCss(css, `vue-${id}`);
|
|
246
|
+
code += "\nexport default __sfc__;\n";
|
|
247
|
+
return { contents: code, loader: lang };
|
|
248
|
+
}
|
|
249
|
+
async function compileYaml(path, text) {
|
|
250
|
+
const yaml = await load("yaml");
|
|
251
|
+
try {
|
|
252
|
+
return { contents: `export default ${JSON.stringify((yaml.load || yaml.default.load)(text))};`, loader: "js" };
|
|
253
|
+
} catch (e) {
|
|
254
|
+
throw Object.assign(new Error(e.reason || e.message), { loc: e.mark ? { line: e.mark.line + 1, column: e.mark.column } : null });
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return async function transform(path, text) {
|
|
258
|
+
if (!TRANSFORM_EXT.test(path) || typeof text !== "string") return null;
|
|
259
|
+
try {
|
|
260
|
+
let r;
|
|
261
|
+
if (/\.svelte(\.[jt]s)?$/.test(path)) r = await compileSvelte(path, text);
|
|
262
|
+
else if (path.endsWith(".vue")) r = await compileVue(path, text);
|
|
263
|
+
else if (/\.s[ac]ss$/.test(path)) r = { contents: await compileSass(path, text), loader: "css" };
|
|
264
|
+
else if (path.endsWith(".less")) r = { contents: await compileLess(path, text), loader: "css" };
|
|
265
|
+
else r = await compileYaml(path, text);
|
|
266
|
+
return { ...r, resolveDir: "/" + dirname(path) };
|
|
267
|
+
} catch (e) {
|
|
268
|
+
return fail(e.file || path, e.message.split("\n")[0], e.loc);
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// ../esbuild-plugin-browser/src/index.js
|
|
274
|
+
var LOADERS = { ts: "ts", mts: "ts", cts: "ts", tsx: "tsx", js: "js", mjs: "js", cjs: "js", jsx: "jsx", json: "json", css: "css", svg: "text", html: "text", txt: "text", md: "text" };
|
|
275
|
+
var EXTS = ["", ".ts", ".tsx", ".js", ".jsx", ".mjs", ".json", ".css", ".svelte.ts", ".svelte.js", "/index.ts", "/index.tsx", "/index.js"];
|
|
276
|
+
function readDeps(files) {
|
|
277
|
+
if (!files.has("package.json")) return {};
|
|
278
|
+
try {
|
|
279
|
+
const v = files.get("package.json");
|
|
280
|
+
return JSON.parse(typeof v === "string" ? v : new TextDecoder().decode(v)).dependencies || {};
|
|
281
|
+
} catch {
|
|
282
|
+
return {};
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function browserPlugin(o) {
|
|
286
|
+
const {
|
|
287
|
+
files,
|
|
288
|
+
esbuild,
|
|
289
|
+
cdn = "https://esm.sh",
|
|
290
|
+
sharedRuntimes = SHARED_RUNTIMES,
|
|
291
|
+
transform = true,
|
|
292
|
+
prod = false,
|
|
293
|
+
resolvePackage,
|
|
294
|
+
cache,
|
|
295
|
+
log = {}
|
|
296
|
+
} = o;
|
|
297
|
+
if (!files || typeof files.has !== "function" || typeof files.get !== "function") throw new Error("files には has / get を持つもの(Map など)を渡してください");
|
|
298
|
+
const deps = o.dependencies || readDeps(files);
|
|
299
|
+
const transformer = transform && esbuild ? createTransformer({ files, esbuild, deps, prod, log, ...typeof transform === "object" ? transform : {} }) : null;
|
|
300
|
+
const http = httpPlugin({ cache, log });
|
|
301
|
+
const warned = /* @__PURE__ */ new Set();
|
|
302
|
+
return {
|
|
303
|
+
name: "browser",
|
|
304
|
+
setup(b) {
|
|
305
|
+
http.setup(b);
|
|
306
|
+
b.onResolve({ filter: /^(\.{0,2}\/|[^@\w])/ }, (a) => {
|
|
307
|
+
if (a.namespace === "http") return void 0;
|
|
308
|
+
const base = normalize(a.path.startsWith("/") ? a.path : `${dirname(a.importer)}/${a.path}`);
|
|
309
|
+
for (const e of EXTS) if (files.has(base + e)) return { path: base + e, namespace: "vfs" };
|
|
310
|
+
const ts = base.replace(/\.js$/, ".ts");
|
|
311
|
+
if (ts !== base && files.has(ts)) return { path: ts, namespace: "vfs" };
|
|
312
|
+
return { errors: [{ text: `ファイルが見つかりません: ${a.path}` }] };
|
|
313
|
+
});
|
|
314
|
+
b.onResolve({ filter: /^[@\w]/ }, async (a) => {
|
|
315
|
+
if (a.kind === "entry-point") return { path: normalize(a.path), namespace: "vfs" };
|
|
316
|
+
if (a.namespace === "http") return void 0;
|
|
317
|
+
const { name, sub } = parseSpecifier(a.path);
|
|
318
|
+
const range = deps[name];
|
|
319
|
+
if (!range) {
|
|
320
|
+
if (!warned.has(name)) {
|
|
321
|
+
warned.add(name);
|
|
322
|
+
log.warn?.(`${name} が package.json にありません(最新版を CDN から読みます)`);
|
|
323
|
+
}
|
|
324
|
+
return { path: esmShUrl(cdn, name, "", sub, { shared: sharedRuntimes.test(name) }), namespace: "http" };
|
|
325
|
+
}
|
|
326
|
+
if (sharedRuntimes.test(name)) return { path: esmShUrl(cdn, name, range, sub, { shared: true }), namespace: "http" };
|
|
327
|
+
const local = resolvePackage && await resolvePackage(name, sub, range);
|
|
328
|
+
if (local) return { path: normalize(local), namespace: "vfs" };
|
|
329
|
+
return { path: esmShUrl(cdn, name, range, sub), namespace: "http" };
|
|
330
|
+
});
|
|
331
|
+
b.onLoad({ filter: /.*/, namespace: "vfs" }, async (a) => {
|
|
332
|
+
if (!files.has(a.path)) return { errors: [{ text: `ファイルが見つかりません: ${a.path}` }] };
|
|
333
|
+
const content = files.get(a.path);
|
|
334
|
+
if (transformer) {
|
|
335
|
+
const t = await transformer(a.path, content);
|
|
336
|
+
if (t) return t;
|
|
337
|
+
}
|
|
338
|
+
if (content instanceof Uint8Array) return { contents: content, loader: "dataurl" };
|
|
339
|
+
return { contents: content, loader: LOADERS[ext(a.path)] || "text", resolveDir: "/" + dirname(a.path) };
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
42
345
|
// src/config.js
|
|
43
346
|
var CONFIG = {
|
|
44
347
|
FIELDS: {
|
|
@@ -85,7 +388,6 @@ var KintonePluginIDE = (() => {
|
|
|
85
388
|
var BINARY_PREFIX = "base64:";
|
|
86
389
|
var SETTINGS_KEY = "kintone-plugin-ide:settings";
|
|
87
390
|
var NODE_MODULES = "node_modules/";
|
|
88
|
-
var SHARED_RUNTIMES = /^(svelte|vue|@vue\/.+|react|react-dom|preact|solid-js|lit|@lit\/.+)$/;
|
|
89
391
|
var isObj = (v) => v && typeof v === "object" && !Array.isArray(v);
|
|
90
392
|
function merge(target, src) {
|
|
91
393
|
for (const [k, v] of Object.entries(src)) {
|
|
@@ -113,10 +415,10 @@ var KintonePluginIDE = (() => {
|
|
|
113
415
|
if (!res.ok) throw new Error(`ファイルの取得に失敗しました (${res.status})`);
|
|
114
416
|
return new Uint8Array(await res.arrayBuffer());
|
|
115
417
|
}
|
|
116
|
-
async function uploadFile(
|
|
418
|
+
async function uploadFile(bytes2, name, type = "application/octet-stream") {
|
|
117
419
|
const form = new FormData();
|
|
118
420
|
form.append("__REQUEST_TOKEN__", kintone.getRequestToken());
|
|
119
|
-
form.append("file", new Blob([
|
|
421
|
+
form.append("file", new Blob([bytes2], { type }), name);
|
|
120
422
|
const res = await fetch(apiUrl("/k/v1/file.json"), { method: "POST", headers: { "X-Requested-With": "XMLHttpRequest" }, body: form });
|
|
121
423
|
if (!res.ok) throw new Error(`アップロードに失敗しました (${res.status})`);
|
|
122
424
|
return (await res.json()).fileKey;
|
|
@@ -138,7 +440,7 @@ var KintonePluginIDE = (() => {
|
|
|
138
440
|
}
|
|
139
441
|
};
|
|
140
442
|
|
|
141
|
-
// node_modules/fflate/esm/browser.js
|
|
443
|
+
// ../../node_modules/fflate/esm/browser.js
|
|
142
444
|
var u8 = Uint8Array;
|
|
143
445
|
var u16 = Uint16Array;
|
|
144
446
|
var i32 = Int32Array;
|
|
@@ -1140,8 +1442,8 @@ var KintonePluginIDE = (() => {
|
|
|
1140
1442
|
var kb = (n) => `${(n / 1024).toFixed(1)} KB`;
|
|
1141
1443
|
|
|
1142
1444
|
// src/util/path.js
|
|
1143
|
-
var
|
|
1144
|
-
var
|
|
1445
|
+
var dirname2 = (p) => p.split("/").slice(0, -1).join("/");
|
|
1446
|
+
var normalize2 = (p) => {
|
|
1145
1447
|
const out = [];
|
|
1146
1448
|
for (const s of String(p).split("/")) {
|
|
1147
1449
|
if (!s || s === ".") continue;
|
|
@@ -1150,8 +1452,8 @@ var KintonePluginIDE = (() => {
|
|
|
1150
1452
|
}
|
|
1151
1453
|
return out.join("/");
|
|
1152
1454
|
};
|
|
1153
|
-
var
|
|
1154
|
-
var langOf = (p) => ({ ts: "typescript", tsx: "typescript", mts: "typescript", js: "javascript", jsx: "javascript", mjs: "javascript", json: "json", css: "css", html: "html", md: "markdown", svelte: "svelte", vue: "vue", scss: "scss", sass: "sass", less: "less", yaml: "yaml", yml: "yaml" })[
|
|
1455
|
+
var ext2 = (p) => p.split(".").pop().toLowerCase();
|
|
1456
|
+
var langOf = (p) => ({ ts: "typescript", tsx: "typescript", mts: "typescript", js: "javascript", jsx: "javascript", mjs: "javascript", json: "json", css: "css", html: "html", md: "markdown", svelte: "svelte", vue: "vue", scss: "scss", sass: "sass", less: "less", yaml: "yaml", yml: "yaml" })[ext2(p)] || "plaintext";
|
|
1155
1457
|
var isVendor = (p) => p === "node_modules" || p.startsWith(NODE_MODULES);
|
|
1156
1458
|
var safeName = (s) => String(s).replace(/[\\/:*?"<>|]/g, "_");
|
|
1157
1459
|
|
|
@@ -1161,27 +1463,27 @@ var KintonePluginIDE = (() => {
|
|
|
1161
1463
|
const f = record[F.source]?.value?.[0];
|
|
1162
1464
|
if (f) {
|
|
1163
1465
|
const entries = unzipSync(await downloadFile(f.fileKey));
|
|
1164
|
-
for (const [raw,
|
|
1165
|
-
const p =
|
|
1466
|
+
for (const [raw, bytes2] of Object.entries(entries)) {
|
|
1467
|
+
const p = normalize2(raw);
|
|
1166
1468
|
if (!p || isVendor(p)) continue;
|
|
1167
1469
|
if (raw.endsWith("/")) dirs.add(p);
|
|
1168
|
-
else files.set(p, fromBytes(
|
|
1470
|
+
else files.set(p, fromBytes(bytes2));
|
|
1169
1471
|
}
|
|
1170
1472
|
return { files, dirs, from: "zip", name: f.name };
|
|
1171
1473
|
}
|
|
1172
1474
|
const L = F.legacy;
|
|
1173
1475
|
for (const row of record[L?.files]?.value || []) {
|
|
1174
1476
|
const raw = row.value[L.path].value || "";
|
|
1175
|
-
const p =
|
|
1477
|
+
const p = normalize2(raw);
|
|
1176
1478
|
if (!p || isVendor(p)) continue;
|
|
1177
1479
|
if (raw.endsWith("/")) dirs.add(p);
|
|
1178
1480
|
else files.set(p, row.value[L.content].value || "");
|
|
1179
1481
|
}
|
|
1180
1482
|
return { files, dirs, from: files.size || dirs.size ? "legacy" : "empty" };
|
|
1181
1483
|
}
|
|
1182
|
-
function createState({ files:
|
|
1183
|
-
const files = new Map(
|
|
1184
|
-
const saved = from === "legacy" ? /* @__PURE__ */ new Map() : new Map(
|
|
1484
|
+
function createState({ files: loaded2, dirs: loadedDirs, from }) {
|
|
1485
|
+
const files = new Map(loaded2);
|
|
1486
|
+
const saved = from === "legacy" ? /* @__PURE__ */ new Map() : new Map(loaded2);
|
|
1185
1487
|
const dirs = new Set(loadedDirs);
|
|
1186
1488
|
const savedDirs = new Set(from === "legacy" ? [] : loadedDirs);
|
|
1187
1489
|
const sourcePaths = () => [...files.keys()].filter((p) => !isVendor(p));
|
|
@@ -1216,8 +1518,8 @@ var KintonePluginIDE = (() => {
|
|
|
1216
1518
|
for (const c of children) if (c != null) e.append(c);
|
|
1217
1519
|
return e;
|
|
1218
1520
|
};
|
|
1219
|
-
function downloadBlob(
|
|
1220
|
-
const url = URL.createObjectURL(new Blob([
|
|
1521
|
+
function downloadBlob(bytes2, name, type = "application/zip") {
|
|
1522
|
+
const url = URL.createObjectURL(new Blob([bytes2], { type }));
|
|
1221
1523
|
el("a", { href: url, download: name }).click();
|
|
1222
1524
|
setTimeout(() => URL.revokeObjectURL(url), 1e4);
|
|
1223
1525
|
}
|
|
@@ -1471,11 +1773,6 @@ var KintonePluginIDE = (() => {
|
|
|
1471
1773
|
}
|
|
1472
1774
|
|
|
1473
1775
|
// src/npm/registry.js
|
|
1474
|
-
function parseSpecifier(spec) {
|
|
1475
|
-
const parts = spec.split("/");
|
|
1476
|
-
const n = spec.startsWith("@") ? 2 : 1;
|
|
1477
|
-
return { name: parts.slice(0, n).join("/"), sub: parts.length > n ? "/" + parts.slice(n).join("/") : "" };
|
|
1478
|
-
}
|
|
1479
1776
|
function parseInstallArg(arg) {
|
|
1480
1777
|
const at = arg.lastIndexOf("@");
|
|
1481
1778
|
return at > 0 ? { name: arg.slice(0, at), range: arg.slice(at + 1) } : { name: arg, range: "" };
|
|
@@ -1513,10 +1810,10 @@ var KintonePluginIDE = (() => {
|
|
|
1513
1810
|
this.name = "NotFoundError";
|
|
1514
1811
|
}
|
|
1515
1812
|
};
|
|
1516
|
-
var strip = (f) =>
|
|
1813
|
+
var strip = (f) => normalize2(String(f).replace(/^file:\/\/\//, "").replace(/[?#].*$/, ""));
|
|
1517
1814
|
var AMBIENT_TYPES = { svelte: (range) => `https://cdn.jsdelivr.net/npm/svelte@${encodeURIComponent(range)}/types/index.d.ts` };
|
|
1518
1815
|
var SCRIPT = /\.(m?tsx?|m?jsx?)$/;
|
|
1519
|
-
var
|
|
1816
|
+
var EXTS2 = [".ts", ".tsx", ".mts", ".js", ".jsx", ".mjs", ".d.ts", "/index.ts", "/index.tsx", "/index.js"];
|
|
1520
1817
|
var DEFAULT_TSCONFIG = JSON.stringify({
|
|
1521
1818
|
compilerOptions: { target: "ES2020", strict: true, types: [CONFIG.CDN.kintoneDts, "kintone-plugin-ide-env"] }
|
|
1522
1819
|
}, null, 2) + "\n";
|
|
@@ -1539,8 +1836,8 @@ var KintonePluginIDE = (() => {
|
|
|
1539
1836
|
for (const m of text.matchAll(/(?:from\s*|import\s*\(?\s*)['"](\.{1,2}\/[^'"]+)['"]/g)) {
|
|
1540
1837
|
const spec = m[1];
|
|
1541
1838
|
if (/\.(m?[tj]sx?|json|css)$/.test(spec)) continue;
|
|
1542
|
-
const base =
|
|
1543
|
-
const hit =
|
|
1839
|
+
const base = normalize2(`${dirname2(p)}/${spec}`);
|
|
1840
|
+
const hit = EXTS2.map((e) => base + e).find((c) => files.has(c));
|
|
1544
1841
|
if (hit) map[spec] = `/${hit}`;
|
|
1545
1842
|
}
|
|
1546
1843
|
if (Object.keys(map).length) scopes[`/${p}`] = map;
|
|
@@ -1801,7 +2098,7 @@ ${t.replace(/^\/\/\/ <reference types=.*$/gm, "")}`);
|
|
|
1801
2098
|
links.push({
|
|
1802
2099
|
range: { start: { x, y }, end: { x: x + [...m[0]].length - 1, y } },
|
|
1803
2100
|
text: m[0],
|
|
1804
|
-
activate: () => m[4] ? window.open(m[4], "_blank") : ctx.openFile(
|
|
2101
|
+
activate: () => m[4] ? window.open(m[4], "_blank") : ctx.openFile(normalize2(m[1]), +m[2], +(m[3] || 1))
|
|
1805
2102
|
});
|
|
1806
2103
|
}
|
|
1807
2104
|
cb(links);
|
|
@@ -1846,7 +2143,7 @@ ${t.replace(/^\/\/\/ <reference types=.*$/gm, "")}`);
|
|
|
1846
2143
|
const m = el("div", { className: "kpi-menu" });
|
|
1847
2144
|
m.dataset.fileTreeContextMenuRoot = "true";
|
|
1848
2145
|
const isDir = item.kind === "directory";
|
|
1849
|
-
const path =
|
|
2146
|
+
const path = normalize2(item.path);
|
|
1850
2147
|
const vendor = isVendor(path);
|
|
1851
2148
|
const add = (label, fn, disabled = false) => {
|
|
1852
2149
|
const b = el("button", { textContent: label, disabled });
|
|
@@ -1857,7 +2154,7 @@ ${t.replace(/^\/\/\/ <reference types=.*$/gm, "")}`);
|
|
|
1857
2154
|
};
|
|
1858
2155
|
m.append(b);
|
|
1859
2156
|
};
|
|
1860
|
-
const dir = isDir ? path :
|
|
2157
|
+
const dir = isDir ? path : dirname2(path);
|
|
1861
2158
|
add("新しいファイル", () => newFile(dir), vendor);
|
|
1862
2159
|
add("新しいフォルダ", () => newFolder(dir), vendor);
|
|
1863
2160
|
add("ファイルをアップロード…", () => uploadFiles(dir), vendor);
|
|
@@ -1884,14 +2181,14 @@ ${t.replace(/^\/\/\/ <reference types=.*$/gm, "")}`);
|
|
|
1884
2181
|
portal = m;
|
|
1885
2182
|
return el("span");
|
|
1886
2183
|
}
|
|
1887
|
-
const vendorGuard = (paths) => !paths.some((p) => isVendor(
|
|
2184
|
+
const vendorGuard = (paths) => !paths.some((p) => isVendor(normalize2(p)));
|
|
1888
2185
|
const tree = new FileTree({
|
|
1889
2186
|
paths: treePaths(),
|
|
1890
2187
|
initialExpansion: "open",
|
|
1891
2188
|
flattenEmptyDirectories: false,
|
|
1892
2189
|
// node_modules/dayjs のように1行にまとめない
|
|
1893
2190
|
search: true,
|
|
1894
|
-
renaming: { canRename: ({ path }) => !isVendor(
|
|
2191
|
+
renaming: { canRename: ({ path }) => !isVendor(normalize2(path)) },
|
|
1895
2192
|
dragAndDrop: {
|
|
1896
2193
|
canDrag: vendorGuard,
|
|
1897
2194
|
canDrop: ({ target }) => !JSON.stringify(target ?? "").includes(NODE_MODULES)
|
|
@@ -1900,13 +2197,13 @@ ${t.replace(/^\/\/\/ <reference types=.*$/gm, "")}`);
|
|
|
1900
2197
|
contextMenu: { enabled: true, triggerMode: "both", buttonVisibility: "when-needed", render: menu, onClose: closePortal }
|
|
1901
2198
|
},
|
|
1902
2199
|
onSelectionChange: (paths) => {
|
|
1903
|
-
const p = paths[0] &&
|
|
2200
|
+
const p = paths[0] && normalize2(paths[0]);
|
|
1904
2201
|
if (p && files.has(p)) ctx.openFile(p);
|
|
1905
2202
|
},
|
|
1906
2203
|
unsafeCSS: TREE_CSS
|
|
1907
2204
|
});
|
|
1908
2205
|
tree.onMutation("move", ({ from, to }) => {
|
|
1909
|
-
const f =
|
|
2206
|
+
const f = normalize2(from), t = normalize2(to);
|
|
1910
2207
|
const isFolder = from.endsWith("/") || dirs.has(f) || !files.has(f) && [...files.keys()].some((k) => k.startsWith(f + "/"));
|
|
1911
2208
|
movePath(f, t, isFolder);
|
|
1912
2209
|
});
|
|
@@ -1938,7 +2235,7 @@ ${t.replace(/^\/\/\/ <reference types=.*$/gm, "")}`);
|
|
|
1938
2235
|
}
|
|
1939
2236
|
const has = (p) => files.has(p) || dirs.has(p) || [...files.keys()].some((k) => k.startsWith(p + "/"));
|
|
1940
2237
|
const checkPath = (kind) => (v) => {
|
|
1941
|
-
const p =
|
|
2238
|
+
const p = normalize2(v);
|
|
1942
2239
|
if (!p) return "名前を入れてください";
|
|
1943
2240
|
if (isVendor(p)) return "node_modules の中には作れません(npm install を使ってください)";
|
|
1944
2241
|
if (/[\\:*?"<>|]/.test(p)) return "使えない文字が入っています";
|
|
@@ -1953,17 +2250,17 @@ ${t.replace(/^\/\/\/ <reference types=.*$/gm, "")}`);
|
|
|
1953
2250
|
const v = await ctx.ask({ title: "新しいファイル", message: "フォルダは / で区切ります。末尾を / にするとフォルダを作ります", value: prefix + "new-file.ts", select: nameRange(prefix, "new-file.ts"), validate: checkPath("file"), ok: "作る" });
|
|
1954
2251
|
if (v == null) return;
|
|
1955
2252
|
if (v.endsWith("/")) {
|
|
1956
|
-
makeFolder(
|
|
2253
|
+
makeFolder(normalize2(v));
|
|
1957
2254
|
return;
|
|
1958
2255
|
}
|
|
1959
|
-
const p =
|
|
2256
|
+
const p = normalize2(v);
|
|
1960
2257
|
addFiles([[p, ""]]);
|
|
1961
2258
|
ctx.openFile(p);
|
|
1962
2259
|
}
|
|
1963
2260
|
async function newFolder(dir) {
|
|
1964
2261
|
const prefix = dir ? `${dir}/` : "";
|
|
1965
2262
|
const v = await ctx.ask({ title: "新しいフォルダ", value: prefix + "new-folder", select: [prefix.length, prefix.length + 10], validate: checkPath("folder"), ok: "作る" });
|
|
1966
|
-
if (v != null) makeFolder(
|
|
2263
|
+
if (v != null) makeFolder(normalize2(v));
|
|
1967
2264
|
}
|
|
1968
2265
|
function makeFolder(p) {
|
|
1969
2266
|
if (!p || has(p)) return;
|
|
@@ -1982,13 +2279,13 @@ ${t.replace(/^\/\/\/ <reference types=.*$/gm, "")}`);
|
|
|
1982
2279
|
const prefix = dir ? `${dir}/` : "";
|
|
1983
2280
|
let targets;
|
|
1984
2281
|
if (list.length === 1) {
|
|
1985
|
-
const v = await ctx.ask({ title: `${list[0].name} をアップロード`, message: `置く場所(パス)を指定してください(${kb(list[0].size)})`, value: prefix + list[0].name, select: nameRange(prefix, list[0].name), validate: (x) =>
|
|
2282
|
+
const v = await ctx.ask({ title: `${list[0].name} をアップロード`, message: `置く場所(パス)を指定してください(${kb(list[0].size)})`, value: prefix + list[0].name, select: nameRange(prefix, list[0].name), validate: (x) => normalize2(x) ? isVendor(normalize2(x)) ? "node_modules の中には置けません" : null : "パスを入れてください", ok: "アップロード" });
|
|
1986
2283
|
if (v == null) return;
|
|
1987
|
-
targets = [[
|
|
2284
|
+
targets = [[normalize2(v), list[0]]];
|
|
1988
2285
|
} else {
|
|
1989
|
-
const v = await ctx.ask({ title: `${list.length} 個のファイルをアップロード`, message: list.map((f) => f.name).join("\n"), value: dir || "image", validate: (x) => isVendor(
|
|
2286
|
+
const v = await ctx.ask({ title: `${list.length} 個のファイルをアップロード`, message: list.map((f) => f.name).join("\n"), value: dir || "image", validate: (x) => isVendor(normalize2(x)) ? "node_modules の中には置けません" : null, ok: "アップロード" });
|
|
1990
2287
|
if (v == null) return;
|
|
1991
|
-
targets = list.map((f) => [
|
|
2288
|
+
targets = list.map((f) => [normalize2(`${normalize2(v)}/${f.name}`), f]);
|
|
1992
2289
|
}
|
|
1993
2290
|
const exists = targets.filter(([p]) => files.has(p)).map(([p]) => p);
|
|
1994
2291
|
if (exists.length && !await ctx.confirm("上書きします", exists.join("\n"), { ok: "上書きする", danger: true })) return;
|
|
@@ -2132,15 +2429,15 @@ ${targets.slice(0, 30).join("\n")}${targets.length > 30 ? "\n…" : ""}`, { ok:
|
|
|
2132
2429
|
function showBinary(p) {
|
|
2133
2430
|
closeDiff();
|
|
2134
2431
|
closePreview();
|
|
2135
|
-
const
|
|
2136
|
-
const mime = MIME[
|
|
2432
|
+
const bytes2 = toBytes(files.get(p));
|
|
2433
|
+
const mime = MIME[ext2(p)];
|
|
2137
2434
|
const dl = el("button", { className: "kpi-btn", textContent: "ダウンロード" });
|
|
2138
|
-
dl.onclick = () => downloadBlob(
|
|
2435
|
+
dl.onclick = () => downloadBlob(bytes2, p.split("/").pop(), mime || "application/octet-stream");
|
|
2139
2436
|
preview = el(
|
|
2140
2437
|
"div",
|
|
2141
2438
|
{ className: "kpi-preview" },
|
|
2142
|
-
mime ? el("img", { src: `data:${mime};base64,${b64(
|
|
2143
|
-
el("div", {}, `${p} ・ ${kb(
|
|
2439
|
+
mime ? el("img", { src: `data:${mime};base64,${b64(bytes2)}`, alt: p }) : el("div", { textContent: "バイナリファイル" }),
|
|
2440
|
+
el("div", {}, `${p} ・ ${kb(bytes2.length)}`),
|
|
2144
2441
|
dl
|
|
2145
2442
|
);
|
|
2146
2443
|
if (mime) preview.querySelector("img").onload = (e) => {
|
|
@@ -2232,7 +2529,7 @@ ${targets.slice(0, 30).join("\n")}${targets.length > 30 ? "\n…" : ""}`, { ok:
|
|
|
2232
2529
|
workspaceFS.sync();
|
|
2233
2530
|
await markersSettled();
|
|
2234
2531
|
const markers = monaco.editor.getModelMarkers({}).filter((m) => {
|
|
2235
|
-
const p =
|
|
2532
|
+
const p = normalize2(m.resource.path);
|
|
2236
2533
|
return models.has(p) && !isVendor(p);
|
|
2237
2534
|
});
|
|
2238
2535
|
const errs = markers.filter((m) => m.severity >= 8);
|
|
@@ -2240,7 +2537,7 @@ ${targets.slice(0, 30).join("\n")}${targets.length > 30 ? "\n…" : ""}`, { ok:
|
|
|
2240
2537
|
ctx.problems = { errors: errs.length, warnings: warns.length };
|
|
2241
2538
|
ctx.updateStatus();
|
|
2242
2539
|
if (!quiet || errs.length) {
|
|
2243
|
-
for (const m of [...errs, ...warns]) (m.severity >= 8 ? log.error : log.warn)(`${
|
|
2540
|
+
for (const m of [...errs, ...warns]) (m.severity >= 8 ? log.error : log.warn)(`${normalize2(m.resource.path)}:${m.startLineNumber}:${m.startColumn} ${m.message.split("\n")[0]}`);
|
|
2244
2541
|
if (!markers.length) log.ok("型チェック: 問題なし");
|
|
2245
2542
|
}
|
|
2246
2543
|
return errs.length;
|
|
@@ -2250,7 +2547,7 @@ ${targets.slice(0, 30).join("\n")}${targets.length > 30 ? "\n…" : ""}`, { ok:
|
|
|
2250
2547
|
const { prettier, plugins } = await loadPrettier();
|
|
2251
2548
|
let n = 0;
|
|
2252
2549
|
for (const p of paths) {
|
|
2253
|
-
const parser = PARSERS[
|
|
2550
|
+
const parser = PARSERS[ext2(p)];
|
|
2254
2551
|
if (!parser || isVendor(p) || isBinary(files.get(p))) continue;
|
|
2255
2552
|
const out = await prettier.format(files.get(p), { parser, plugins, singleQuote: true, printWidth: 100 });
|
|
2256
2553
|
if (out !== files.get(p)) {
|
|
@@ -2379,155 +2676,6 @@ ${targets.slice(0, 30).join("\n")}${targets.length > 30 ? "\n…" : ""}`, { ok:
|
|
|
2379
2676
|
}
|
|
2380
2677
|
}
|
|
2381
2678
|
|
|
2382
|
-
// src/build/transformers.js
|
|
2383
|
-
var TRANSFORM_EXT = /\.(svelte|svelte\.[jt]s|vue|s[ac]ss|less|ya?ml)$/;
|
|
2384
|
-
var fail = (path, message, loc) => ({ errors: [{ text: message, location: loc ? { file: path, line: loc.line, column: loc.column ?? 0 } : { file: path } }] });
|
|
2385
|
-
var injectCss = (css, id) => css.trim() ? `
|
|
2386
|
-
;(()=>{if(typeof document==='undefined'||document.getElementById(${JSON.stringify(id)}))return;const s=document.createElement('style');s.id=${JSON.stringify(id)};s.textContent=${JSON.stringify(css)};document.head.appendChild(s)})();
|
|
2387
|
-
` : "";
|
|
2388
|
-
var hashId = (s) => {
|
|
2389
|
-
let h = 5381;
|
|
2390
|
-
for (let i = 0; i < s.length; i++) h = (h << 5) + h + s.charCodeAt(i) >>> 0;
|
|
2391
|
-
return h.toString(36);
|
|
2392
|
-
};
|
|
2393
|
-
function createTransformer({ files, log, prod, load, esbuild, deps }) {
|
|
2394
|
-
const need = (name) => {
|
|
2395
|
-
if (!deps[name]) throw new Error(`${name} が package.json にありません。npm install ${name} してください(ランタイムとコンパイラのバージョンをそろえるため)`);
|
|
2396
|
-
return deps[name];
|
|
2397
|
-
};
|
|
2398
|
-
async function compileSass(path, text) {
|
|
2399
|
-
const sass = await load("sass");
|
|
2400
|
-
const toUrl = (p) => new URL(`file:///${p}`);
|
|
2401
|
-
const candidates = (p) => {
|
|
2402
|
-
const d = dirname(p), b = p.split("/").pop();
|
|
2403
|
-
const bases = /\.(s[ac]ss|css)$/.test(b) ? [p] : [`${p}.scss`, `${p}.sass`, `${p}.css`, `${d ? d + "/" : ""}_${b}.scss`, `${d ? d + "/" : ""}_${b}.sass`, `${p}/index.scss`, `${p}/_index.scss`];
|
|
2404
|
-
return bases.map(normalize);
|
|
2405
|
-
};
|
|
2406
|
-
const importer = {
|
|
2407
|
-
canonicalize(url, ctx) {
|
|
2408
|
-
const base = ctx && ctx.containingUrl ? ctx.containingUrl.pathname.slice(1) : path;
|
|
2409
|
-
const raw = url.startsWith("file:///") ? url.slice(8) : normalize(`${dirname(base)}/${url}`);
|
|
2410
|
-
const hit = candidates(raw).find((c) => files.has(c));
|
|
2411
|
-
return hit ? toUrl(hit) : null;
|
|
2412
|
-
},
|
|
2413
|
-
load(u) {
|
|
2414
|
-
const p = decodeURIComponent(u.pathname.slice(1));
|
|
2415
|
-
return { contents: files.get(p), syntax: p.endsWith(".sass") ? "indented" : p.endsWith(".css") ? "css" : "scss" };
|
|
2416
|
-
}
|
|
2417
|
-
};
|
|
2418
|
-
try {
|
|
2419
|
-
const r = sass.compileString(text, { url: toUrl(path), syntax: path.endsWith(".sass") ? "indented" : "scss", importers: [importer], style: prod ? "compressed" : "expanded", silenceDeprecations: ["import"] });
|
|
2420
|
-
return r.css;
|
|
2421
|
-
} catch (e) {
|
|
2422
|
-
const s = e.span;
|
|
2423
|
-
throw Object.assign(new Error(e.sassMessage || e.message), { loc: s ? { line: s.start.line + 1, column: s.start.column } : null, file: s && s.url ? s.url.pathname.slice(1) : path });
|
|
2424
|
-
}
|
|
2425
|
-
}
|
|
2426
|
-
async function compileLess(path, text) {
|
|
2427
|
-
const mod = await load("less");
|
|
2428
|
-
const less = mod.default || mod;
|
|
2429
|
-
const vfs = {
|
|
2430
|
-
install(lessObj, pm) {
|
|
2431
|
-
class VfsFileManager extends lessObj.FileManager {
|
|
2432
|
-
supports() {
|
|
2433
|
-
return true;
|
|
2434
|
-
}
|
|
2435
|
-
supportsSync() {
|
|
2436
|
-
return false;
|
|
2437
|
-
}
|
|
2438
|
-
loadFile(filename, currentDirectory) {
|
|
2439
|
-
const base = normalize(`${currentDirectory || dirname(path)}/${filename}`);
|
|
2440
|
-
const hit = [base, `${base}.less`, `${base}.css`].find((c) => files.has(c));
|
|
2441
|
-
return hit ? Promise.resolve({ contents: files.get(hit), filename: hit }) : Promise.reject({ type: "File", message: `ファイルが見つかりません: ${filename}` });
|
|
2442
|
-
}
|
|
2443
|
-
}
|
|
2444
|
-
pm.addFileManager(new VfsFileManager());
|
|
2445
|
-
}
|
|
2446
|
-
};
|
|
2447
|
-
try {
|
|
2448
|
-
return (await less.render(text, { filename: path, plugins: [vfs], compress: prod })).css;
|
|
2449
|
-
} catch (e) {
|
|
2450
|
-
throw Object.assign(new Error(e.message), { loc: e.line ? { line: e.line, column: e.column || 0 } : null, file: e.filename || path });
|
|
2451
|
-
}
|
|
2452
|
-
}
|
|
2453
|
-
async function compileSvelte(path, text) {
|
|
2454
|
-
const svelte = await load("svelte", need("svelte"));
|
|
2455
|
-
const warn = (w) => log.warn(`${path}${w.start ? `:${w.start.line}:${w.start.column + 1}` : ""} ${w.message}`);
|
|
2456
|
-
try {
|
|
2457
|
-
if (/\.svelte\.[jt]s$/.test(path)) {
|
|
2458
|
-
const js = path.endsWith(".ts") ? (await esbuild.transform(text, { loader: "ts", sourcefile: path })).code : text;
|
|
2459
|
-
const r2 = svelte.compileModule(js, { filename: path, generate: "client", dev: !prod });
|
|
2460
|
-
r2.warnings.forEach(warn);
|
|
2461
|
-
return { contents: r2.js.code, loader: "js" };
|
|
2462
|
-
}
|
|
2463
|
-
const r = svelte.compile(text, { filename: path, generate: "client", dev: !prod, css: "injected" });
|
|
2464
|
-
r.warnings.forEach(warn);
|
|
2465
|
-
return { contents: r.js.code, loader: "js" };
|
|
2466
|
-
} catch (e) {
|
|
2467
|
-
throw Object.assign(new Error(e.message), { loc: e.start ? { line: e.start.line, column: e.start.column } : null });
|
|
2468
|
-
}
|
|
2469
|
-
}
|
|
2470
|
-
async function compileVue(path, text) {
|
|
2471
|
-
const sfc = await load("vue", need("vue"));
|
|
2472
|
-
const { descriptor, errors } = sfc.parse(text, { filename: path });
|
|
2473
|
-
if (errors.length) {
|
|
2474
|
-
const e = errors[0];
|
|
2475
|
-
throw Object.assign(new Error(e.message), { loc: e.loc ? { line: e.loc.start.line, column: e.loc.start.column - 1 } : null });
|
|
2476
|
-
}
|
|
2477
|
-
const id = hashId(path);
|
|
2478
|
-
const scoped = descriptor.styles.some((s) => s.scoped);
|
|
2479
|
-
let code = "", lang = "js";
|
|
2480
|
-
if (descriptor.script || descriptor.scriptSetup) {
|
|
2481
|
-
const s = sfc.compileScript(descriptor, { id, inlineTemplate: true, isProd: prod, genDefaultAs: "__sfc__", templateOptions: { compilerOptions: { scopeId: scoped ? `data-v-${id}` : void 0 } } });
|
|
2482
|
-
code = s.content;
|
|
2483
|
-
lang = /tsx?/.test((descriptor.scriptSetup || descriptor.script).lang || "") ? "ts" : "js";
|
|
2484
|
-
} else code = "const __sfc__ = {};";
|
|
2485
|
-
if (descriptor.template && !descriptor.scriptSetup) {
|
|
2486
|
-
const t = sfc.compileTemplate({ source: descriptor.template.content, filename: path, id, scoped, isProd: prod, compilerOptions: { scopeId: scoped ? `data-v-${id}` : void 0 } });
|
|
2487
|
-
if (t.errors.length) throw new Error(String(t.errors[0].message || t.errors[0]));
|
|
2488
|
-
code += `
|
|
2489
|
-
${t.code.replace(/\nexport (function|const) (render|ssrRender)/, "\n$1 $2")}
|
|
2490
|
-
__sfc__.render = render;`;
|
|
2491
|
-
}
|
|
2492
|
-
if (scoped) code += `
|
|
2493
|
-
__sfc__.__scopeId = "data-v-${id}";`;
|
|
2494
|
-
let css = "";
|
|
2495
|
-
for (const st of descriptor.styles) {
|
|
2496
|
-
let source = st.content;
|
|
2497
|
-
if (/^s[ac]ss$/.test(st.lang || "")) source = await compileSass(`${path}.${st.lang}`, source);
|
|
2498
|
-
else if (st.lang === "less") source = await compileLess(`${path}.less`, source);
|
|
2499
|
-
const r = sfc.compileStyle({ source, filename: path, id: `data-v-${id}`, scoped: st.scoped, isProd: prod });
|
|
2500
|
-
if (r.errors.length) throw new Error(String(r.errors[0].message || r.errors[0]));
|
|
2501
|
-
css += r.code + "\n";
|
|
2502
|
-
}
|
|
2503
|
-
code += injectCss(css, `vue-${id}`);
|
|
2504
|
-
code += "\nexport default __sfc__;\n";
|
|
2505
|
-
return { contents: code, loader: lang };
|
|
2506
|
-
}
|
|
2507
|
-
async function compileYaml(path, text) {
|
|
2508
|
-
const yaml = await load("yaml");
|
|
2509
|
-
try {
|
|
2510
|
-
return { contents: `export default ${JSON.stringify((yaml.load || yaml.default.load)(text))};`, loader: "js" };
|
|
2511
|
-
} catch (e) {
|
|
2512
|
-
throw Object.assign(new Error(e.reason || e.message), { loc: e.mark ? { line: e.mark.line + 1, column: e.mark.column } : null });
|
|
2513
|
-
}
|
|
2514
|
-
}
|
|
2515
|
-
return async function transform(path, text) {
|
|
2516
|
-
if (!TRANSFORM_EXT.test(path) || isBinary(text)) return null;
|
|
2517
|
-
try {
|
|
2518
|
-
let r;
|
|
2519
|
-
if (/\.svelte(\.[jt]s)?$/.test(path)) r = await compileSvelte(path, text);
|
|
2520
|
-
else if (path.endsWith(".vue")) r = await compileVue(path, text);
|
|
2521
|
-
else if (/\.s[ac]ss$/.test(path)) r = { contents: await compileSass(path, text), loader: "css" };
|
|
2522
|
-
else if (path.endsWith(".less")) r = { contents: await compileLess(path, text), loader: "css" };
|
|
2523
|
-
else r = await compileYaml(path, text);
|
|
2524
|
-
return { ...r, resolveDir: "/" + dirname(path) };
|
|
2525
|
-
} catch (e) {
|
|
2526
|
-
return fail(e.file || path, e.message.split("\n")[0], e.loc);
|
|
2527
|
-
}
|
|
2528
|
-
};
|
|
2529
|
-
}
|
|
2530
|
-
|
|
2531
2679
|
// src/util/idb.js
|
|
2532
2680
|
var open = () => new Promise((resolve, reject) => {
|
|
2533
2681
|
const r = indexedDB.open("kintone-plugin-ide", 1);
|
|
@@ -2554,33 +2702,6 @@ __sfc__.__scopeId = "data-v-${id}";`;
|
|
|
2554
2702
|
var idbSet = (key, value) => tx("readwrite", (s) => s.put(value, key)).catch(() => {
|
|
2555
2703
|
});
|
|
2556
2704
|
|
|
2557
|
-
// src/build/http-plugin.js
|
|
2558
|
-
var immutable = (u) => /@\d+\.\d+\.\d+(-[\w.]+)?\//.test(u) && !/[\^~*]/.test(decodeURIComponent(u));
|
|
2559
|
-
function httpPlugin(log, cache = /* @__PURE__ */ new Map()) {
|
|
2560
|
-
return {
|
|
2561
|
-
name: "http",
|
|
2562
|
-
setup(b) {
|
|
2563
|
-
b.onResolve({ filter: /^https?:\/\// }, (a) => ({ path: a.path, namespace: "http" }));
|
|
2564
|
-
b.onResolve({ filter: /.*/, namespace: "http" }, (a) => ({ path: new URL(a.path, a.importer).href, namespace: "http" }));
|
|
2565
|
-
b.onLoad({ filter: /.*/, namespace: "http" }, async (a) => {
|
|
2566
|
-
if (!cache.has(a.path)) {
|
|
2567
|
-
const keep = immutable(a.path);
|
|
2568
|
-
let text = keep ? await idbGet(`http:${a.path}`) : void 0;
|
|
2569
|
-
if (text === void 0) {
|
|
2570
|
-
log?.info(`取得: ${a.path.replace(CONFIG.CDN.npm, "esm.sh")}`);
|
|
2571
|
-
const res = await fetch(a.path);
|
|
2572
|
-
if (!res.ok) throw new Error(`${res.status} ${a.path}`);
|
|
2573
|
-
text = await res.text();
|
|
2574
|
-
if (keep) await idbSet(`http:${a.path}`, text);
|
|
2575
|
-
}
|
|
2576
|
-
cache.set(a.path, text);
|
|
2577
|
-
}
|
|
2578
|
-
return { contents: cache.get(a.path), loader: /\.css(\?|$)/.test(a.path) ? "css" : "js" };
|
|
2579
|
-
});
|
|
2580
|
-
}
|
|
2581
|
-
};
|
|
2582
|
-
}
|
|
2583
|
-
|
|
2584
2705
|
// src/npm/vendor.js
|
|
2585
2706
|
var pkgDir = (name) => `${NODE_MODULES}${name}/`;
|
|
2586
2707
|
var subFile = (name, sub) => `${pkgDir(name)}${sub.slice(1)}${/\.(css|mjs|js)$/.test(sub) ? "" : ".mjs"}`;
|
|
@@ -2601,7 +2722,7 @@ __sfc__.__scopeId = "data-v-${id}";`;
|
|
|
2601
2722
|
target: "es2020",
|
|
2602
2723
|
logLevel: "silent",
|
|
2603
2724
|
legalComments: "inline",
|
|
2604
|
-
plugins: [httpPlugin(log)]
|
|
2725
|
+
plugins: [httpPlugin({ log, cache: { get: idbGet, set: idbSet } })]
|
|
2605
2726
|
});
|
|
2606
2727
|
return r.outputFiles[0].text;
|
|
2607
2728
|
}
|
|
@@ -2640,63 +2761,14 @@ __sfc__.__scopeId = "data-v-${id}";`;
|
|
|
2640
2761
|
return [subFile(name, sub), text];
|
|
2641
2762
|
}
|
|
2642
2763
|
|
|
2643
|
-
// src/build/vfs-plugin.js
|
|
2644
|
-
var LOADERS = { ts: "ts", mts: "ts", tsx: "tsx", js: "js", mjs: "js", jsx: "jsx", json: "json", css: "css", svg: "text", html: "text", txt: "text", md: "text" };
|
|
2645
|
-
var EXTS2 = ["", ".ts", ".tsx", ".js", ".jsx", ".mjs", ".json", ".css", ".svelte.ts", ".svelte.js", "/index.ts", "/index.tsx", "/index.js"];
|
|
2646
|
-
function vfsPlugin(files, log, { vendor, transform } = {}) {
|
|
2647
|
-
const deps = readPackageJson(files).dependencies;
|
|
2648
|
-
const warned = /* @__PURE__ */ new Set();
|
|
2649
|
-
const http = httpPlugin(log);
|
|
2650
|
-
return {
|
|
2651
|
-
name: "kintone-vfs",
|
|
2652
|
-
setup(b) {
|
|
2653
|
-
http.setup(b);
|
|
2654
|
-
b.onResolve({ filter: /^(\.{0,2}\/|[^@\w])/ }, (a) => {
|
|
2655
|
-
if (a.namespace === "http") return void 0;
|
|
2656
|
-
const base = normalize(a.path.startsWith("/") ? a.path : `${dirname(a.importer)}/${a.path}`);
|
|
2657
|
-
for (const e of EXTS2) if (files.has(base + e)) return { path: base + e, namespace: "vfs" };
|
|
2658
|
-
const ts = base.replace(/\.js$/, ".ts");
|
|
2659
|
-
if (ts !== base && files.has(ts)) return { path: ts, namespace: "vfs" };
|
|
2660
|
-
return { errors: [{ text: `ファイルが見つかりません: ${a.path}` }] };
|
|
2661
|
-
});
|
|
2662
|
-
b.onResolve({ filter: /^[@\w]/ }, async (a) => {
|
|
2663
|
-
if (a.kind === "entry-point") return { path: normalize(a.path), namespace: "vfs" };
|
|
2664
|
-
if (a.namespace === "http") return void 0;
|
|
2665
|
-
const { name, sub } = parseSpecifier(a.path);
|
|
2666
|
-
if (!deps[name]) {
|
|
2667
|
-
if (!warned.has(name)) {
|
|
2668
|
-
warned.add(name);
|
|
2669
|
-
log.warn(`${name} が package.json にありません(最新版を CDN から直接使います)。npm install ${name} で node_modules に入ります`);
|
|
2670
|
-
}
|
|
2671
|
-
return { path: npmUrl(name, "", sub), namespace: "http" };
|
|
2672
|
-
}
|
|
2673
|
-
if (SHARED_RUNTIMES.test(name)) return { path: npmUrl(name, deps[name], sub, { shared: true }), namespace: "http" };
|
|
2674
|
-
const target = sub ? subFile(name, sub) : `${pkgDir(name)}index.mjs`;
|
|
2675
|
-
if (files.has(target)) return { path: target, namespace: "vfs" };
|
|
2676
|
-
const got = vendor && await vendor(name, sub);
|
|
2677
|
-
if (got) return { path: got, namespace: "vfs" };
|
|
2678
|
-
return { path: npmUrl(name, deps[name], sub), namespace: "http" };
|
|
2679
|
-
});
|
|
2680
|
-
b.onLoad({ filter: /.*/, namespace: "vfs" }, async (a) => {
|
|
2681
|
-
if (!files.has(a.path)) return { errors: [{ text: `ファイルが見つかりません: ${a.path}` }] };
|
|
2682
|
-
const text = files.get(a.path);
|
|
2683
|
-
const t = transform && await transform(a.path, text);
|
|
2684
|
-
if (t) return t;
|
|
2685
|
-
if (isBinary(text)) return { contents: toBytes(text), loader: "dataurl" };
|
|
2686
|
-
return { contents: text, loader: LOADERS[ext(a.path)] || "text", resolveDir: "/" + dirname(a.path) };
|
|
2687
|
-
});
|
|
2688
|
-
}
|
|
2689
|
-
};
|
|
2690
|
-
}
|
|
2691
|
-
|
|
2692
2764
|
// src/build/build.js
|
|
2693
2765
|
function sourceList(manifest) {
|
|
2694
2766
|
const list = [];
|
|
2695
2767
|
for (const [k, t] of [["desktop", "js"], ["desktop", "css"], ["mobile", "js"], ["mobile", "css"], ["config", "js"], ["config", "css"]]) {
|
|
2696
|
-
for (const f of manifest[k] && manifest[k][t] || []) if (!/^https?:\/\//.test(f)) list.push(
|
|
2768
|
+
for (const f of manifest[k] && manifest[k][t] || []) if (!/^https?:\/\//.test(f)) list.push(normalize2(f));
|
|
2697
2769
|
}
|
|
2698
|
-
if (manifest.config && manifest.config.html) list.push(
|
|
2699
|
-
list.push("manifest.json",
|
|
2770
|
+
if (manifest.config && manifest.config.html) list.push(normalize2(manifest.config.html));
|
|
2771
|
+
list.push("manifest.json", normalize2(manifest.icon));
|
|
2700
2772
|
return [...new Set(list)];
|
|
2701
2773
|
}
|
|
2702
2774
|
var entryCandidates = (out) => {
|
|
@@ -2708,9 +2780,9 @@ __sfc__.__scopeId = "data-v-${id}";`;
|
|
|
2708
2780
|
try {
|
|
2709
2781
|
const validate = await loadValidator();
|
|
2710
2782
|
const r = validate(manifest, {
|
|
2711
|
-
relativePath: (p) => outputs.has(
|
|
2712
|
-
maxFileSize: (max2, p) => !outputs.has(
|
|
2713
|
-
fileExists: (p) => outputs.has(
|
|
2783
|
+
relativePath: (p) => outputs.has(normalize2(p)),
|
|
2784
|
+
maxFileSize: (max2, p) => !outputs.has(normalize2(p)) || outputs.get(normalize2(p)).length <= max2,
|
|
2785
|
+
fileExists: (p) => outputs.has(normalize2(p))
|
|
2714
2786
|
});
|
|
2715
2787
|
for (const w of r.warnings || []) log.warn(`manifest.json: ${w.message}`);
|
|
2716
2788
|
if (!r.valid) {
|
|
@@ -2738,7 +2810,26 @@ __sfc__.__scopeId = "data-v-${id}";`;
|
|
|
2738
2810
|
const manifest = readManifest(files);
|
|
2739
2811
|
const outputs = /* @__PURE__ */ new Map();
|
|
2740
2812
|
const es = await loadEsbuild();
|
|
2741
|
-
const
|
|
2813
|
+
const source = { has: (p) => files.has(p), get: (p) => {
|
|
2814
|
+
const t = files.get(p);
|
|
2815
|
+
return t !== void 0 && isBinary(t) ? toBytes(t) : t;
|
|
2816
|
+
} };
|
|
2817
|
+
const resolvePackage = async (name, sub) => {
|
|
2818
|
+
const target = sub ? subFile(name, sub) : `${pkgDir(name)}index.mjs`;
|
|
2819
|
+
if (files.has(target)) return target;
|
|
2820
|
+
return vendor ? vendor(name, sub) : null;
|
|
2821
|
+
};
|
|
2822
|
+
const plugin = () => browserPlugin({
|
|
2823
|
+
files: source,
|
|
2824
|
+
esbuild: es,
|
|
2825
|
+
prod,
|
|
2826
|
+
cdn: CONFIG.CDN.npm,
|
|
2827
|
+
resolvePackage,
|
|
2828
|
+
dependencies: readPackageJson(files).dependencies,
|
|
2829
|
+
transform: { load: loadCompiler },
|
|
2830
|
+
cache: { get: idbGet, set: idbSet },
|
|
2831
|
+
log: { info: log.info, warn: (t) => log.warn(/package\.json にありません/.test(t) ? `${t}。npm install で node_modules に入ります` : t) }
|
|
2832
|
+
});
|
|
2742
2833
|
for (const out of sourceList(manifest)) {
|
|
2743
2834
|
if (files.has(out) && !isVendor(out)) {
|
|
2744
2835
|
outputs.set(out, toBytes(files.get(out)));
|
|
@@ -2765,7 +2856,7 @@ __sfc__.__scopeId = "data-v-${id}";`;
|
|
|
2765
2856
|
__VUE_PROD_DEVTOOLS__: "false",
|
|
2766
2857
|
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: "false"
|
|
2767
2858
|
},
|
|
2768
|
-
plugins: [
|
|
2859
|
+
plugins: [plugin()]
|
|
2769
2860
|
}).catch((e) => e);
|
|
2770
2861
|
for (const w of r.warnings || []) log.warn(fmtMsg(w));
|
|
2771
2862
|
if (r.errors && r.errors.length) {
|
|
@@ -2782,9 +2873,19 @@ __sfc__.__scopeId = "data-v-${id}";`;
|
|
|
2782
2873
|
return { manifest, contentsZip: zipSync(entries, { level: 9 }), outputs };
|
|
2783
2874
|
}
|
|
2784
2875
|
|
|
2785
|
-
// src/
|
|
2876
|
+
// ../web-signer/src/index.js
|
|
2786
2877
|
var ALG = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-1" };
|
|
2787
2878
|
var RSA_ALG = new Uint8Array([48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0]);
|
|
2879
|
+
var subtle = () => {
|
|
2880
|
+
if (!globalThis.crypto || !globalThis.crypto.subtle) throw new Error("Web Crypto (crypto.subtle) が使えない環境です");
|
|
2881
|
+
return globalThis.crypto.subtle;
|
|
2882
|
+
};
|
|
2883
|
+
var b642 = (u82) => {
|
|
2884
|
+
let s = "";
|
|
2885
|
+
for (let i = 0; i < u82.length; i += 32768) s += String.fromCharCode(...u82.subarray(i, i + 32768));
|
|
2886
|
+
return btoa(s);
|
|
2887
|
+
};
|
|
2888
|
+
var unb642 = (s) => Uint8Array.from(atob(s), (c) => c.charCodeAt(0));
|
|
2788
2889
|
var derLen = (n) => n < 128 ? [n] : n < 256 ? [129, n] : [130, n >> 8, n & 255];
|
|
2789
2890
|
var cat = (...a) => {
|
|
2790
2891
|
const o = new Uint8Array(a.reduce((s, x) => s + x.length, 0));
|
|
@@ -2795,16 +2896,17 @@ __sfc__.__scopeId = "data-v-${id}";`;
|
|
|
2795
2896
|
}
|
|
2796
2897
|
return o;
|
|
2797
2898
|
};
|
|
2798
|
-
var pemBody = (pem) =>
|
|
2899
|
+
var pemBody = (pem) => unb642(String(pem).replace(/-----[^-]+-----|\s/g, ""));
|
|
2799
2900
|
var toPem = (der, label) => `-----BEGIN ${label}-----
|
|
2800
|
-
${
|
|
2901
|
+
${b642(der).match(/.{1,64}/g).join("\n")}
|
|
2801
2902
|
-----END ${label}-----
|
|
2802
2903
|
`;
|
|
2803
|
-
var
|
|
2904
|
+
var bytes = (x) => x instanceof Uint8Array ? x : typeof x === "string" ? new TextEncoder().encode(x) : new Uint8Array(x);
|
|
2905
|
+
function pkcs1ToPkcs8(p1) {
|
|
2804
2906
|
const body = cat(new Uint8Array([2, 1, 0]), RSA_ALG, cat(new Uint8Array([4, ...derLen(p1.length)]), p1));
|
|
2805
2907
|
return cat(new Uint8Array([48, ...derLen(body.length)]), body);
|
|
2806
|
-
}
|
|
2807
|
-
|
|
2908
|
+
}
|
|
2909
|
+
function pkcs8ToPkcs1(p8) {
|
|
2808
2910
|
let i = 0;
|
|
2809
2911
|
const len = () => {
|
|
2810
2912
|
let l2 = p8[i++];
|
|
@@ -2827,32 +2929,56 @@ ${b64(der).match(/.{1,64}/g).join("\n")}
|
|
|
2827
2929
|
i++;
|
|
2828
2930
|
const l = len();
|
|
2829
2931
|
return p8.slice(i, i + l);
|
|
2830
|
-
}
|
|
2932
|
+
}
|
|
2933
|
+
async function importPpk(ppk) {
|
|
2934
|
+
const der = pemBody(ppk);
|
|
2935
|
+
const p8 = /BEGIN PRIVATE KEY/.test(ppk) ? der : pkcs1ToPkcs8(der);
|
|
2936
|
+
return subtle().importKey("pkcs8", p8, ALG, true, ["sign"]);
|
|
2937
|
+
}
|
|
2831
2938
|
async function generateKey() {
|
|
2832
|
-
const kp = await
|
|
2833
|
-
return toPem(
|
|
2939
|
+
const kp = await subtle().generateKey({ ...ALG, modulusLength: 1024, publicExponent: new Uint8Array([1, 0, 1]) }, true, ["sign", "verify"]);
|
|
2940
|
+
return toPem(pkcs8ToPkcs1(new Uint8Array(await subtle().exportKey("pkcs8", kp.privateKey))), "RSA PRIVATE KEY");
|
|
2834
2941
|
}
|
|
2835
|
-
async function
|
|
2836
|
-
const hex = [...new Uint8Array(await
|
|
2942
|
+
async function pluginIdFromPublicKey(spki) {
|
|
2943
|
+
const hex = [...new Uint8Array(await subtle().digest("SHA-256", bytes(spki)))].map((b) => b.toString(16).padStart(2, "0")).join("").slice(0, 32);
|
|
2837
2944
|
return hex.replace(/[0-9a-f]/g, (c) => "abcdefghijklmnop"["0123456789abcdef".indexOf(c)]);
|
|
2838
2945
|
}
|
|
2946
|
+
var idFromSpki = pluginIdFromPublicKey;
|
|
2947
|
+
async function publicKeyFromPpk(ppk) {
|
|
2948
|
+
const jwk = await subtle().exportKey("jwk", await importPpk(ppk));
|
|
2949
|
+
const pub = await subtle().importKey("jwk", { kty: "RSA", n: jwk.n, e: jwk.e, alg: "RS1", ext: true }, ALG, true, ["verify"]);
|
|
2950
|
+
const spki = new Uint8Array(await subtle().exportKey("spki", pub));
|
|
2951
|
+
return { publicKey: spki, id: await pluginIdFromPublicKey(spki) };
|
|
2952
|
+
}
|
|
2839
2953
|
async function pack(contentsZip, ppk) {
|
|
2840
|
-
const
|
|
2841
|
-
const
|
|
2842
|
-
const
|
|
2843
|
-
const
|
|
2844
|
-
|
|
2845
|
-
|
|
2954
|
+
const data = bytes(contentsZip);
|
|
2955
|
+
const key = await importPpk(ppk);
|
|
2956
|
+
const signature = new Uint8Array(await subtle().sign(ALG, key, data));
|
|
2957
|
+
const { publicKey, id } = await publicKeyFromPpk(ppk);
|
|
2958
|
+
return { id, plugin: zipSync({ "contents.zip": data, PUBKEY: publicKey, SIGNATURE: signature }) };
|
|
2959
|
+
}
|
|
2960
|
+
async function packFiles(files, ppk) {
|
|
2961
|
+
const entries = {};
|
|
2962
|
+
for (const [p, v] of Object.entries(files)) entries[p.replace(/^\.?\//, "")] = bytes(v);
|
|
2963
|
+
if (!entries["manifest.json"]) throw new Error("manifest.json がありません");
|
|
2964
|
+
const key = ppk || await generateKey();
|
|
2965
|
+
const { id, plugin } = await pack(zipSync(entries, { level: 9 }), key);
|
|
2966
|
+
return { id, plugin, ppk: key };
|
|
2846
2967
|
}
|
|
2847
2968
|
async function unpack(pluginZip) {
|
|
2848
|
-
const outer = unzipSync(pluginZip);
|
|
2969
|
+
const outer = unzipSync(bytes(pluginZip));
|
|
2849
2970
|
if (!outer["contents.zip"]) return null;
|
|
2850
2971
|
let verified = false;
|
|
2851
2972
|
if (outer.PUBKEY && outer.SIGNATURE) {
|
|
2852
|
-
const pub = await
|
|
2853
|
-
verified = await
|
|
2973
|
+
const pub = await subtle().importKey("spki", outer.PUBKEY, ALG, false, ["verify"]);
|
|
2974
|
+
verified = await subtle().verify(ALG, pub, outer.SIGNATURE, outer["contents.zip"]);
|
|
2854
2975
|
}
|
|
2855
|
-
return {
|
|
2976
|
+
return {
|
|
2977
|
+
contents: unzipSync(outer["contents.zip"]),
|
|
2978
|
+
contentsZip: outer["contents.zip"],
|
|
2979
|
+
verified,
|
|
2980
|
+
id: outer.PUBKEY ? await pluginIdFromPublicKey(outer.PUBKEY) : null
|
|
2981
|
+
};
|
|
2856
2982
|
}
|
|
2857
2983
|
|
|
2858
2984
|
// src/ide/actions/release.js
|
|
@@ -2910,17 +3036,17 @@ ${location.hostname} / ${id}` } });
|
|
|
2910
3036
|
// src/ide/actions/zip.js
|
|
2911
3037
|
function setupZip(ctx) {
|
|
2912
3038
|
const { state, log, ui } = ctx;
|
|
2913
|
-
async function importZipBytes(
|
|
2914
|
-
const unpacked = await unpack(
|
|
3039
|
+
async function importZipBytes(bytes2, name) {
|
|
3040
|
+
const unpacked = await unpack(bytes2).catch(() => null);
|
|
2915
3041
|
let entries;
|
|
2916
3042
|
if (unpacked) {
|
|
2917
3043
|
log.info(`${name} はプラグインです(署名 ${unpacked.verified ? "OK" : "NG"}, ID ${unpacked.id})。中身を取り込みます`);
|
|
2918
3044
|
entries = unpacked.contents;
|
|
2919
|
-
} else entries = unzipSync(
|
|
3045
|
+
} else entries = unzipSync(bytes2);
|
|
2920
3046
|
const paths = Object.keys(entries).filter((p) => !p.endsWith("/") && !p.startsWith("__MACOSX/") && !/(^|\/)\.DS_Store$/.test(p) && !/\.ppk$/.test(p));
|
|
2921
3047
|
const mf = paths.filter((p) => /(^|\/)manifest\.json$/.test(p) && !p.includes("node_modules/")).sort((a, b) => a.length - b.length)[0];
|
|
2922
3048
|
const root = mf ? mf.slice(0, -"manifest.json".length) : "";
|
|
2923
|
-
const list = paths.filter((p) => p.startsWith(root)).map((p) => [
|
|
3049
|
+
const list = paths.filter((p) => p.startsWith(root)).map((p) => [normalize2(p.slice(root.length)), entries[p]]).filter(([p]) => !isVendor(p)).map(([p, b]) => [p, fromBytes(b)]);
|
|
2924
3050
|
if (!list.length) throw new Error("取り込めるファイルがありませんでした");
|
|
2925
3051
|
if (state.sourcePaths().length && !await ctx.confirm(`${list.length} 個のファイルを取り込みます`, "同じパスのファイルは上書きされます", { ok: "取り込む" })) return;
|
|
2926
3052
|
ctx.addFiles(list);
|
|
@@ -2957,7 +3083,7 @@ ${location.hostname} / ${id}` } });
|
|
|
2957
3083
|
e.preventDefault();
|
|
2958
3084
|
ctx.run(async () => {
|
|
2959
3085
|
if (/\.zip$/i.test(f.name)) await importZipBytes(new Uint8Array(await f.arrayBuffer()), f.name);
|
|
2960
|
-
else await ctx.uploadFiles(ctx.current && !isVendor(ctx.current) ?
|
|
3086
|
+
else await ctx.uploadFiles(ctx.current && !isVendor(ctx.current) ? dirname2(ctx.current) : "", list);
|
|
2961
3087
|
});
|
|
2962
3088
|
}, true);
|
|
2963
3089
|
}
|
|
@@ -3377,22 +3503,22 @@ ${location.hostname} / ${id}` } });
|
|
|
3377
3503
|
case "check":
|
|
3378
3504
|
return ctx.typecheck();
|
|
3379
3505
|
case "format":
|
|
3380
|
-
return ctx.formatFiles(sub ? [
|
|
3506
|
+
return ctx.formatFiles(sub ? [normalize2(sub)] : state.sourcePaths());
|
|
3381
3507
|
case "version":
|
|
3382
3508
|
return ctx.bumpVersion(sub || "patch");
|
|
3383
3509
|
case "grep":
|
|
3384
3510
|
case "search":
|
|
3385
3511
|
return ctx.grep(args.slice(1).join(" "), { all: flags.includes("--all") });
|
|
3386
3512
|
case "open":
|
|
3387
|
-
return ctx.openFile(
|
|
3513
|
+
return ctx.openFile(normalize2(sub || ""));
|
|
3388
3514
|
case "touch": {
|
|
3389
|
-
const p =
|
|
3515
|
+
const p = normalize2(sub || "");
|
|
3390
3516
|
if (!p) return log.warn("touch <path>");
|
|
3391
3517
|
if (!state.files.has(p)) ctx.addFiles([[p, ""]]);
|
|
3392
3518
|
return ctx.openFile(p);
|
|
3393
3519
|
}
|
|
3394
3520
|
case "mkdir":
|
|
3395
|
-
return sub ? ctx.makeFolder(
|
|
3521
|
+
return sub ? ctx.makeFolder(normalize2(sub)) : log.warn("mkdir <path>");
|
|
3396
3522
|
case "sample": {
|
|
3397
3523
|
const files = SAMPLES[sub];
|
|
3398
3524
|
if (!files) return log.error(`sample ${Object.keys(SAMPLES).join(" | ")}`);
|
|
@@ -3406,9 +3532,9 @@ ${location.hostname} / ${id}` } });
|
|
|
3406
3532
|
return ctx.npmRestore();
|
|
3407
3533
|
}
|
|
3408
3534
|
case "upload":
|
|
3409
|
-
return ctx.uploadFiles(sub ?
|
|
3535
|
+
return ctx.uploadFiles(sub ? normalize2(sub) : "");
|
|
3410
3536
|
case "diff":
|
|
3411
|
-
return sub === "off" ? ctx.closeDiff() : ctx.showDiff(sub ?
|
|
3537
|
+
return sub === "off" ? ctx.closeDiff() : ctx.showDiff(sub ? normalize2(sub) : ctx.current);
|
|
3412
3538
|
case "import":
|
|
3413
3539
|
return ctx.importZip();
|
|
3414
3540
|
case "export":
|