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/LICENSE +21 -21
- package/README.md +125 -123
- package/dist/index.js +41 -315
- package/dist/kintone-plugin-ide.iife.js +442 -316
- package/package.json +62 -59
- package/src/build/build.js +104 -87
- package/src/config.js +56 -58
- package/src/deps.js +41 -41
- package/src/ide/actions/misc.js +74 -74
- package/src/ide/actions/npm.js +103 -103
- package/src/ide/actions/release.js +57 -57
- package/src/ide/actions/save.js +54 -54
- package/src/ide/actions/zip.js +59 -59
- package/src/ide/commands.js +96 -96
- package/src/ide/css.js +50 -50
- package/src/ide/dialog.js +51 -51
- package/src/ide/editor.js +155 -155
- package/src/ide/index.js +94 -94
- package/src/ide/layout.js +89 -89
- package/src/ide/sample.js +168 -168
- package/src/ide/state.js +58 -58
- package/src/ide/terminal.js +57 -57
- package/src/ide/tree.js +224 -224
- package/src/ide/workspace-fs.js +173 -173
- package/src/index.js +49 -48
- package/src/kintone/api.js +24 -24
- package/src/kintone/plugin.js +37 -37
- package/src/npm/registry.js +32 -32
- package/src/npm/vendor.js +69 -69
- package/src/util/bytes.js +15 -15
- package/src/util/dom.js +15 -15
- package/src/util/idb.js +18 -18
- package/src/util/path.js +14 -14
- package/src/util/settings.js +5 -5
- package/types/index.d.ts +49 -49
- 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
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
/* kintone-plugin-ide v0.
|
|
1
|
+
/* kintone-plugin-ide v0.4.0 (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);
|
|
5
5
|
|
|
6
6
|
// src/config.js
|
|
7
|
+
import { SHARED_RUNTIMES } from "esbuild-plugin-browser";
|
|
7
8
|
var CONFIG = {
|
|
8
9
|
FIELDS: {
|
|
9
10
|
source: "source_zip",
|
|
@@ -49,7 +50,6 @@ var F = CONFIG.FIELDS;
|
|
|
49
50
|
var BINARY_PREFIX = "base64:";
|
|
50
51
|
var SETTINGS_KEY = "kintone-plugin-ide:settings";
|
|
51
52
|
var NODE_MODULES = "node_modules/";
|
|
52
|
-
var SHARED_RUNTIMES = /^(svelte|vue|@vue\/.+|react|react-dom|preact|solid-js|lit|@lit\/.+)$/;
|
|
53
53
|
var isObj = (v) => v && typeof v === "object" && !Array.isArray(v);
|
|
54
54
|
function merge(target, src) {
|
|
55
55
|
for (const [k, v] of Object.entries(src)) {
|
|
@@ -461,11 +461,6 @@ function setupLayout(ctx) {
|
|
|
461
461
|
}
|
|
462
462
|
|
|
463
463
|
// src/npm/registry.js
|
|
464
|
-
function parseSpecifier(spec) {
|
|
465
|
-
const parts = spec.split("/");
|
|
466
|
-
const n = spec.startsWith("@") ? 2 : 1;
|
|
467
|
-
return { name: parts.slice(0, n).join("/"), sub: parts.length > n ? "/" + parts.slice(n).join("/") : "" };
|
|
468
|
-
}
|
|
469
464
|
function parseInstallArg(arg) {
|
|
470
465
|
const at = arg.lastIndexOf("@");
|
|
471
466
|
return at > 0 ? { name: arg.slice(0, at), range: arg.slice(at + 1) } : { name: arg, range: "" };
|
|
@@ -1371,155 +1366,10 @@ async function addToTestApp(app, id, log) {
|
|
|
1371
1366
|
|
|
1372
1367
|
// src/build/build.js
|
|
1373
1368
|
import { zipSync as zipSync2 } from "fflate";
|
|
1369
|
+
import { browserPlugin } from "esbuild-plugin-browser";
|
|
1374
1370
|
|
|
1375
|
-
// src/
|
|
1376
|
-
|
|
1377
|
-
var fail = (path, message, loc) => ({ errors: [{ text: message, location: loc ? { file: path, line: loc.line, column: loc.column ?? 0 } : { file: path } }] });
|
|
1378
|
-
var injectCss = (css, id) => css.trim() ? `
|
|
1379
|
-
;(()=>{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)})();
|
|
1380
|
-
` : "";
|
|
1381
|
-
var hashId = (s) => {
|
|
1382
|
-
let h = 5381;
|
|
1383
|
-
for (let i = 0; i < s.length; i++) h = (h << 5) + h + s.charCodeAt(i) >>> 0;
|
|
1384
|
-
return h.toString(36);
|
|
1385
|
-
};
|
|
1386
|
-
function createTransformer({ files, log, prod, load, esbuild, deps }) {
|
|
1387
|
-
const need = (name) => {
|
|
1388
|
-
if (!deps[name]) throw new Error(`${name} が package.json にありません。npm install ${name} してください(ランタイムとコンパイラのバージョンをそろえるため)`);
|
|
1389
|
-
return deps[name];
|
|
1390
|
-
};
|
|
1391
|
-
async function compileSass(path, text) {
|
|
1392
|
-
const sass = await load("sass");
|
|
1393
|
-
const toUrl = (p) => new URL(`file:///${p}`);
|
|
1394
|
-
const candidates = (p) => {
|
|
1395
|
-
const d = dirname(p), b = p.split("/").pop();
|
|
1396
|
-
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`];
|
|
1397
|
-
return bases.map(normalize);
|
|
1398
|
-
};
|
|
1399
|
-
const importer = {
|
|
1400
|
-
canonicalize(url, ctx) {
|
|
1401
|
-
const base = ctx && ctx.containingUrl ? ctx.containingUrl.pathname.slice(1) : path;
|
|
1402
|
-
const raw = url.startsWith("file:///") ? url.slice(8) : normalize(`${dirname(base)}/${url}`);
|
|
1403
|
-
const hit = candidates(raw).find((c) => files.has(c));
|
|
1404
|
-
return hit ? toUrl(hit) : null;
|
|
1405
|
-
},
|
|
1406
|
-
load(u) {
|
|
1407
|
-
const p = decodeURIComponent(u.pathname.slice(1));
|
|
1408
|
-
return { contents: files.get(p), syntax: p.endsWith(".sass") ? "indented" : p.endsWith(".css") ? "css" : "scss" };
|
|
1409
|
-
}
|
|
1410
|
-
};
|
|
1411
|
-
try {
|
|
1412
|
-
const r = sass.compileString(text, { url: toUrl(path), syntax: path.endsWith(".sass") ? "indented" : "scss", importers: [importer], style: prod ? "compressed" : "expanded", silenceDeprecations: ["import"] });
|
|
1413
|
-
return r.css;
|
|
1414
|
-
} catch (e) {
|
|
1415
|
-
const s = e.span;
|
|
1416
|
-
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 });
|
|
1417
|
-
}
|
|
1418
|
-
}
|
|
1419
|
-
async function compileLess(path, text) {
|
|
1420
|
-
const mod = await load("less");
|
|
1421
|
-
const less = mod.default || mod;
|
|
1422
|
-
const vfs = {
|
|
1423
|
-
install(lessObj, pm) {
|
|
1424
|
-
class VfsFileManager extends lessObj.FileManager {
|
|
1425
|
-
supports() {
|
|
1426
|
-
return true;
|
|
1427
|
-
}
|
|
1428
|
-
supportsSync() {
|
|
1429
|
-
return false;
|
|
1430
|
-
}
|
|
1431
|
-
loadFile(filename, currentDirectory) {
|
|
1432
|
-
const base = normalize(`${currentDirectory || dirname(path)}/${filename}`);
|
|
1433
|
-
const hit = [base, `${base}.less`, `${base}.css`].find((c) => files.has(c));
|
|
1434
|
-
return hit ? Promise.resolve({ contents: files.get(hit), filename: hit }) : Promise.reject({ type: "File", message: `ファイルが見つかりません: ${filename}` });
|
|
1435
|
-
}
|
|
1436
|
-
}
|
|
1437
|
-
pm.addFileManager(new VfsFileManager());
|
|
1438
|
-
}
|
|
1439
|
-
};
|
|
1440
|
-
try {
|
|
1441
|
-
return (await less.render(text, { filename: path, plugins: [vfs], compress: prod })).css;
|
|
1442
|
-
} catch (e) {
|
|
1443
|
-
throw Object.assign(new Error(e.message), { loc: e.line ? { line: e.line, column: e.column || 0 } : null, file: e.filename || path });
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
async function compileSvelte(path, text) {
|
|
1447
|
-
const svelte = await load("svelte", need("svelte"));
|
|
1448
|
-
const warn = (w) => log.warn(`${path}${w.start ? `:${w.start.line}:${w.start.column + 1}` : ""} ${w.message}`);
|
|
1449
|
-
try {
|
|
1450
|
-
if (/\.svelte\.[jt]s$/.test(path)) {
|
|
1451
|
-
const js = path.endsWith(".ts") ? (await esbuild.transform(text, { loader: "ts", sourcefile: path })).code : text;
|
|
1452
|
-
const r2 = svelte.compileModule(js, { filename: path, generate: "client", dev: !prod });
|
|
1453
|
-
r2.warnings.forEach(warn);
|
|
1454
|
-
return { contents: r2.js.code, loader: "js" };
|
|
1455
|
-
}
|
|
1456
|
-
const r = svelte.compile(text, { filename: path, generate: "client", dev: !prod, css: "injected" });
|
|
1457
|
-
r.warnings.forEach(warn);
|
|
1458
|
-
return { contents: r.js.code, loader: "js" };
|
|
1459
|
-
} catch (e) {
|
|
1460
|
-
throw Object.assign(new Error(e.message), { loc: e.start ? { line: e.start.line, column: e.start.column } : null });
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
async function compileVue(path, text) {
|
|
1464
|
-
const sfc = await load("vue", need("vue"));
|
|
1465
|
-
const { descriptor, errors } = sfc.parse(text, { filename: path });
|
|
1466
|
-
if (errors.length) {
|
|
1467
|
-
const e = errors[0];
|
|
1468
|
-
throw Object.assign(new Error(e.message), { loc: e.loc ? { line: e.loc.start.line, column: e.loc.start.column - 1 } : null });
|
|
1469
|
-
}
|
|
1470
|
-
const id = hashId(path);
|
|
1471
|
-
const scoped = descriptor.styles.some((s) => s.scoped);
|
|
1472
|
-
let code = "", lang = "js";
|
|
1473
|
-
if (descriptor.script || descriptor.scriptSetup) {
|
|
1474
|
-
const s = sfc.compileScript(descriptor, { id, inlineTemplate: true, isProd: prod, genDefaultAs: "__sfc__", templateOptions: { compilerOptions: { scopeId: scoped ? `data-v-${id}` : void 0 } } });
|
|
1475
|
-
code = s.content;
|
|
1476
|
-
lang = /tsx?/.test((descriptor.scriptSetup || descriptor.script).lang || "") ? "ts" : "js";
|
|
1477
|
-
} else code = "const __sfc__ = {};";
|
|
1478
|
-
if (descriptor.template && !descriptor.scriptSetup) {
|
|
1479
|
-
const t = sfc.compileTemplate({ source: descriptor.template.content, filename: path, id, scoped, isProd: prod, compilerOptions: { scopeId: scoped ? `data-v-${id}` : void 0 } });
|
|
1480
|
-
if (t.errors.length) throw new Error(String(t.errors[0].message || t.errors[0]));
|
|
1481
|
-
code += `
|
|
1482
|
-
${t.code.replace(/\nexport (function|const) (render|ssrRender)/, "\n$1 $2")}
|
|
1483
|
-
__sfc__.render = render;`;
|
|
1484
|
-
}
|
|
1485
|
-
if (scoped) code += `
|
|
1486
|
-
__sfc__.__scopeId = "data-v-${id}";`;
|
|
1487
|
-
let css = "";
|
|
1488
|
-
for (const st of descriptor.styles) {
|
|
1489
|
-
let source = st.content;
|
|
1490
|
-
if (/^s[ac]ss$/.test(st.lang || "")) source = await compileSass(`${path}.${st.lang}`, source);
|
|
1491
|
-
else if (st.lang === "less") source = await compileLess(`${path}.less`, source);
|
|
1492
|
-
const r = sfc.compileStyle({ source, filename: path, id: `data-v-${id}`, scoped: st.scoped, isProd: prod });
|
|
1493
|
-
if (r.errors.length) throw new Error(String(r.errors[0].message || r.errors[0]));
|
|
1494
|
-
css += r.code + "\n";
|
|
1495
|
-
}
|
|
1496
|
-
code += injectCss(css, `vue-${id}`);
|
|
1497
|
-
code += "\nexport default __sfc__;\n";
|
|
1498
|
-
return { contents: code, loader: lang };
|
|
1499
|
-
}
|
|
1500
|
-
async function compileYaml(path, text) {
|
|
1501
|
-
const yaml = await load("yaml");
|
|
1502
|
-
try {
|
|
1503
|
-
return { contents: `export default ${JSON.stringify((yaml.load || yaml.default.load)(text))};`, loader: "js" };
|
|
1504
|
-
} catch (e) {
|
|
1505
|
-
throw Object.assign(new Error(e.reason || e.message), { loc: e.mark ? { line: e.mark.line + 1, column: e.mark.column } : null });
|
|
1506
|
-
}
|
|
1507
|
-
}
|
|
1508
|
-
return async function transform(path, text) {
|
|
1509
|
-
if (!TRANSFORM_EXT.test(path) || isBinary(text)) return null;
|
|
1510
|
-
try {
|
|
1511
|
-
let r;
|
|
1512
|
-
if (/\.svelte(\.[jt]s)?$/.test(path)) r = await compileSvelte(path, text);
|
|
1513
|
-
else if (path.endsWith(".vue")) r = await compileVue(path, text);
|
|
1514
|
-
else if (/\.s[ac]ss$/.test(path)) r = { contents: await compileSass(path, text), loader: "css" };
|
|
1515
|
-
else if (path.endsWith(".less")) r = { contents: await compileLess(path, text), loader: "css" };
|
|
1516
|
-
else r = await compileYaml(path, text);
|
|
1517
|
-
return { ...r, resolveDir: "/" + dirname(path) };
|
|
1518
|
-
} catch (e) {
|
|
1519
|
-
return fail(e.file || path, e.message.split("\n")[0], e.loc);
|
|
1520
|
-
}
|
|
1521
|
-
};
|
|
1522
|
-
}
|
|
1371
|
+
// src/npm/vendor.js
|
|
1372
|
+
import { httpPlugin, SHARED_RUNTIMES as SHARED_RUNTIMES2 } from "esbuild-plugin-browser";
|
|
1523
1373
|
|
|
1524
1374
|
// src/util/idb.js
|
|
1525
1375
|
var open = () => new Promise((resolve, reject) => {
|
|
@@ -1547,33 +1397,6 @@ var idbGet = (key) => tx("readonly", (s) => s.get(key)).catch(() => void 0);
|
|
|
1547
1397
|
var idbSet = (key, value) => tx("readwrite", (s) => s.put(value, key)).catch(() => {
|
|
1548
1398
|
});
|
|
1549
1399
|
|
|
1550
|
-
// src/build/http-plugin.js
|
|
1551
|
-
var immutable = (u) => /@\d+\.\d+\.\d+(-[\w.]+)?\//.test(u) && !/[\^~*]/.test(decodeURIComponent(u));
|
|
1552
|
-
function httpPlugin(log, cache = /* @__PURE__ */ new Map()) {
|
|
1553
|
-
return {
|
|
1554
|
-
name: "http",
|
|
1555
|
-
setup(b) {
|
|
1556
|
-
b.onResolve({ filter: /^https?:\/\// }, (a) => ({ path: a.path, namespace: "http" }));
|
|
1557
|
-
b.onResolve({ filter: /.*/, namespace: "http" }, (a) => ({ path: new URL(a.path, a.importer).href, namespace: "http" }));
|
|
1558
|
-
b.onLoad({ filter: /.*/, namespace: "http" }, async (a) => {
|
|
1559
|
-
if (!cache.has(a.path)) {
|
|
1560
|
-
const keep = immutable(a.path);
|
|
1561
|
-
let text = keep ? await idbGet(`http:${a.path}`) : void 0;
|
|
1562
|
-
if (text === void 0) {
|
|
1563
|
-
log?.info(`取得: ${a.path.replace(CONFIG.CDN.npm, "esm.sh")}`);
|
|
1564
|
-
const res = await fetch(a.path);
|
|
1565
|
-
if (!res.ok) throw new Error(`${res.status} ${a.path}`);
|
|
1566
|
-
text = await res.text();
|
|
1567
|
-
if (keep) await idbSet(`http:${a.path}`, text);
|
|
1568
|
-
}
|
|
1569
|
-
cache.set(a.path, text);
|
|
1570
|
-
}
|
|
1571
|
-
return { contents: cache.get(a.path), loader: /\.css(\?|$)/.test(a.path) ? "css" : "js" };
|
|
1572
|
-
});
|
|
1573
|
-
}
|
|
1574
|
-
};
|
|
1575
|
-
}
|
|
1576
|
-
|
|
1577
1400
|
// src/npm/vendor.js
|
|
1578
1401
|
var pkgDir = (name) => `${NODE_MODULES}${name}/`;
|
|
1579
1402
|
var subFile = (name, sub) => `${pkgDir(name)}${sub.slice(1)}${/\.(css|mjs|js)$/.test(sub) ? "" : ".mjs"}`;
|
|
@@ -1594,13 +1417,13 @@ async function bundle(url, log) {
|
|
|
1594
1417
|
target: "es2020",
|
|
1595
1418
|
logLevel: "silent",
|
|
1596
1419
|
legalComments: "inline",
|
|
1597
|
-
plugins: [httpPlugin(log)]
|
|
1420
|
+
plugins: [httpPlugin({ log, cache: { get: idbGet, set: idbSet } })]
|
|
1598
1421
|
});
|
|
1599
1422
|
return r.outputFiles[0].text;
|
|
1600
1423
|
}
|
|
1601
1424
|
async function fetchPackage(name, range, log, { force = false } = {}) {
|
|
1602
1425
|
const version = await exactVersion(name, range);
|
|
1603
|
-
if (
|
|
1426
|
+
if (SHARED_RUNTIMES2.test(name)) {
|
|
1604
1427
|
return { version, entries: [[`${pkgDir(name)}package.json`, JSON.stringify({ name, version, _range: range, _from: `esm.sh/${name}@${version}`, _note: "ランタイムを共有するパッケージなので、ここには置かずビルド時に esm.sh から読みます" }, null, 2) + "\n"]] };
|
|
1605
1428
|
}
|
|
1606
1429
|
const key = `npm:${name}@${version}`;
|
|
@@ -1633,55 +1456,6 @@ async function fetchSubpath(name, version, sub, log) {
|
|
|
1633
1456
|
return [subFile(name, sub), text];
|
|
1634
1457
|
}
|
|
1635
1458
|
|
|
1636
|
-
// src/build/vfs-plugin.js
|
|
1637
|
-
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" };
|
|
1638
|
-
var EXTS2 = ["", ".ts", ".tsx", ".js", ".jsx", ".mjs", ".json", ".css", ".svelte.ts", ".svelte.js", "/index.ts", "/index.tsx", "/index.js"];
|
|
1639
|
-
function vfsPlugin(files, log, { vendor, transform } = {}) {
|
|
1640
|
-
const deps = readPackageJson(files).dependencies;
|
|
1641
|
-
const warned = /* @__PURE__ */ new Set();
|
|
1642
|
-
const http = httpPlugin(log);
|
|
1643
|
-
return {
|
|
1644
|
-
name: "kintone-vfs",
|
|
1645
|
-
setup(b) {
|
|
1646
|
-
http.setup(b);
|
|
1647
|
-
b.onResolve({ filter: /^(\.{0,2}\/|[^@\w])/ }, (a) => {
|
|
1648
|
-
if (a.namespace === "http") return void 0;
|
|
1649
|
-
const base = normalize(a.path.startsWith("/") ? a.path : `${dirname(a.importer)}/${a.path}`);
|
|
1650
|
-
for (const e of EXTS2) if (files.has(base + e)) return { path: base + e, namespace: "vfs" };
|
|
1651
|
-
const ts = base.replace(/\.js$/, ".ts");
|
|
1652
|
-
if (ts !== base && files.has(ts)) return { path: ts, namespace: "vfs" };
|
|
1653
|
-
return { errors: [{ text: `ファイルが見つかりません: ${a.path}` }] };
|
|
1654
|
-
});
|
|
1655
|
-
b.onResolve({ filter: /^[@\w]/ }, async (a) => {
|
|
1656
|
-
if (a.kind === "entry-point") return { path: normalize(a.path), namespace: "vfs" };
|
|
1657
|
-
if (a.namespace === "http") return void 0;
|
|
1658
|
-
const { name, sub } = parseSpecifier(a.path);
|
|
1659
|
-
if (!deps[name]) {
|
|
1660
|
-
if (!warned.has(name)) {
|
|
1661
|
-
warned.add(name);
|
|
1662
|
-
log.warn(`${name} が package.json にありません(最新版を CDN から直接使います)。npm install ${name} で node_modules に入ります`);
|
|
1663
|
-
}
|
|
1664
|
-
return { path: npmUrl(name, "", sub), namespace: "http" };
|
|
1665
|
-
}
|
|
1666
|
-
if (SHARED_RUNTIMES.test(name)) return { path: npmUrl(name, deps[name], sub, { shared: true }), namespace: "http" };
|
|
1667
|
-
const target = sub ? subFile(name, sub) : `${pkgDir(name)}index.mjs`;
|
|
1668
|
-
if (files.has(target)) return { path: target, namespace: "vfs" };
|
|
1669
|
-
const got = vendor && await vendor(name, sub);
|
|
1670
|
-
if (got) return { path: got, namespace: "vfs" };
|
|
1671
|
-
return { path: npmUrl(name, deps[name], sub), namespace: "http" };
|
|
1672
|
-
});
|
|
1673
|
-
b.onLoad({ filter: /.*/, namespace: "vfs" }, async (a) => {
|
|
1674
|
-
if (!files.has(a.path)) return { errors: [{ text: `ファイルが見つかりません: ${a.path}` }] };
|
|
1675
|
-
const text = files.get(a.path);
|
|
1676
|
-
const t = transform && await transform(a.path, text);
|
|
1677
|
-
if (t) return t;
|
|
1678
|
-
if (isBinary(text)) return { contents: toBytes(text), loader: "dataurl" };
|
|
1679
|
-
return { contents: text, loader: LOADERS[ext(a.path)] || "text", resolveDir: "/" + dirname(a.path) };
|
|
1680
|
-
});
|
|
1681
|
-
}
|
|
1682
|
-
};
|
|
1683
|
-
}
|
|
1684
|
-
|
|
1685
1459
|
// src/build/build.js
|
|
1686
1460
|
function sourceList(manifest) {
|
|
1687
1461
|
const list = [];
|
|
@@ -1731,7 +1505,26 @@ async function buildPlugin(files, log, { prod = false, vendor } = {}) {
|
|
|
1731
1505
|
const manifest = readManifest(files);
|
|
1732
1506
|
const outputs = /* @__PURE__ */ new Map();
|
|
1733
1507
|
const es = await loadEsbuild();
|
|
1734
|
-
const
|
|
1508
|
+
const source = { has: (p) => files.has(p), get: (p) => {
|
|
1509
|
+
const t = files.get(p);
|
|
1510
|
+
return t !== void 0 && isBinary(t) ? toBytes(t) : t;
|
|
1511
|
+
} };
|
|
1512
|
+
const resolvePackage = async (name, sub) => {
|
|
1513
|
+
const target = sub ? subFile(name, sub) : `${pkgDir(name)}index.mjs`;
|
|
1514
|
+
if (files.has(target)) return target;
|
|
1515
|
+
return vendor ? vendor(name, sub) : null;
|
|
1516
|
+
};
|
|
1517
|
+
const plugin = () => browserPlugin({
|
|
1518
|
+
files: source,
|
|
1519
|
+
esbuild: es,
|
|
1520
|
+
prod,
|
|
1521
|
+
cdn: CONFIG.CDN.npm,
|
|
1522
|
+
resolvePackage,
|
|
1523
|
+
dependencies: readPackageJson(files).dependencies,
|
|
1524
|
+
transform: { load: loadCompiler },
|
|
1525
|
+
cache: { get: idbGet, set: idbSet },
|
|
1526
|
+
log: { info: log.info, warn: (t) => log.warn(/package\.json にありません/.test(t) ? `${t}。npm install で node_modules に入ります` : t) }
|
|
1527
|
+
});
|
|
1735
1528
|
for (const out of sourceList(manifest)) {
|
|
1736
1529
|
if (files.has(out) && !isVendor(out)) {
|
|
1737
1530
|
outputs.set(out, toBytes(files.get(out)));
|
|
@@ -1758,7 +1551,7 @@ async function buildPlugin(files, log, { prod = false, vendor } = {}) {
|
|
|
1758
1551
|
__VUE_PROD_DEVTOOLS__: "false",
|
|
1759
1552
|
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: "false"
|
|
1760
1553
|
},
|
|
1761
|
-
plugins: [
|
|
1554
|
+
plugins: [plugin()]
|
|
1762
1555
|
}).catch((e) => e);
|
|
1763
1556
|
for (const w of r.warnings || []) log.warn(fmtMsg(w));
|
|
1764
1557
|
if (r.errors && r.errors.length) {
|
|
@@ -1775,81 +1568,8 @@ async function buildPlugin(files, log, { prod = false, vendor } = {}) {
|
|
|
1775
1568
|
return { manifest, contentsZip: zipSync2(entries, { level: 9 }), outputs };
|
|
1776
1569
|
}
|
|
1777
1570
|
|
|
1778
|
-
// src/packer/packer.js
|
|
1779
|
-
import { zipSync as zipSync3, unzipSync as unzipSync2 } from "fflate";
|
|
1780
|
-
var ALG = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-1" };
|
|
1781
|
-
var RSA_ALG = new Uint8Array([48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0]);
|
|
1782
|
-
var derLen = (n) => n < 128 ? [n] : n < 256 ? [129, n] : [130, n >> 8, n & 255];
|
|
1783
|
-
var cat = (...a) => {
|
|
1784
|
-
const o = new Uint8Array(a.reduce((s, x) => s + x.length, 0));
|
|
1785
|
-
let i = 0;
|
|
1786
|
-
for (const x of a) {
|
|
1787
|
-
o.set(x, i);
|
|
1788
|
-
i += x.length;
|
|
1789
|
-
}
|
|
1790
|
-
return o;
|
|
1791
|
-
};
|
|
1792
|
-
var pemBody = (pem) => unb64(pem.replace(/-----[^-]+-----|\s/g, ""));
|
|
1793
|
-
var toPem = (der, label) => `-----BEGIN ${label}-----
|
|
1794
|
-
${b64(der).match(/.{1,64}/g).join("\n")}
|
|
1795
|
-
-----END ${label}-----
|
|
1796
|
-
`;
|
|
1797
|
-
var p1to8 = (p1) => {
|
|
1798
|
-
const body = cat(new Uint8Array([2, 1, 0]), RSA_ALG, cat(new Uint8Array([4, ...derLen(p1.length)]), p1));
|
|
1799
|
-
return cat(new Uint8Array([48, ...derLen(body.length)]), body);
|
|
1800
|
-
};
|
|
1801
|
-
var p8to1 = (p8) => {
|
|
1802
|
-
let i = 0;
|
|
1803
|
-
const len = () => {
|
|
1804
|
-
let l2 = p8[i++];
|
|
1805
|
-
if (l2 & 128) {
|
|
1806
|
-
const n = l2 & 127;
|
|
1807
|
-
l2 = 0;
|
|
1808
|
-
for (let k = 0; k < n; k++) l2 = l2 << 8 | p8[i++];
|
|
1809
|
-
}
|
|
1810
|
-
return l2;
|
|
1811
|
-
};
|
|
1812
|
-
const skip = () => {
|
|
1813
|
-
i++;
|
|
1814
|
-
const l2 = len();
|
|
1815
|
-
i += l2;
|
|
1816
|
-
};
|
|
1817
|
-
i++;
|
|
1818
|
-
len();
|
|
1819
|
-
skip();
|
|
1820
|
-
skip();
|
|
1821
|
-
i++;
|
|
1822
|
-
const l = len();
|
|
1823
|
-
return p8.slice(i, i + l);
|
|
1824
|
-
};
|
|
1825
|
-
async function generateKey() {
|
|
1826
|
-
const kp = await crypto.subtle.generateKey({ ...ALG, modulusLength: 1024, publicExponent: new Uint8Array([1, 0, 1]) }, true, ["sign", "verify"]);
|
|
1827
|
-
return toPem(p8to1(new Uint8Array(await crypto.subtle.exportKey("pkcs8", kp.privateKey))), "RSA PRIVATE KEY");
|
|
1828
|
-
}
|
|
1829
|
-
async function idFromSpki(spki) {
|
|
1830
|
-
const hex = [...new Uint8Array(await crypto.subtle.digest("SHA-256", spki))].map((b) => b.toString(16).padStart(2, "0")).join("").slice(0, 32);
|
|
1831
|
-
return hex.replace(/[0-9a-f]/g, (c) => "abcdefghijklmnop"["0123456789abcdef".indexOf(c)]);
|
|
1832
|
-
}
|
|
1833
|
-
async function pack(contentsZip, ppk) {
|
|
1834
|
-
const key = await crypto.subtle.importKey("pkcs8", p1to8(pemBody(ppk)), ALG, true, ["sign"]);
|
|
1835
|
-
const signature = new Uint8Array(await crypto.subtle.sign(ALG, key, contentsZip));
|
|
1836
|
-
const jwk = await crypto.subtle.exportKey("jwk", key);
|
|
1837
|
-
const pub = await crypto.subtle.importKey("jwk", { kty: "RSA", n: jwk.n, e: jwk.e, alg: "RS1", ext: true }, ALG, true, ["verify"]);
|
|
1838
|
-
const spki = new Uint8Array(await crypto.subtle.exportKey("spki", pub));
|
|
1839
|
-
return { id: await idFromSpki(spki), plugin: zipSync3({ "contents.zip": contentsZip, PUBKEY: spki, SIGNATURE: signature }) };
|
|
1840
|
-
}
|
|
1841
|
-
async function unpack(pluginZip) {
|
|
1842
|
-
const outer = unzipSync2(pluginZip);
|
|
1843
|
-
if (!outer["contents.zip"]) return null;
|
|
1844
|
-
let verified = false;
|
|
1845
|
-
if (outer.PUBKEY && outer.SIGNATURE) {
|
|
1846
|
-
const pub = await crypto.subtle.importKey("spki", outer.PUBKEY, ALG, false, ["verify"]);
|
|
1847
|
-
verified = await crypto.subtle.verify(ALG, pub, outer.SIGNATURE, outer["contents.zip"]);
|
|
1848
|
-
}
|
|
1849
|
-
return { contents: unzipSync2(outer["contents.zip"]), verified, id: outer.PUBKEY ? await idFromSpki(outer.PUBKEY) : null };
|
|
1850
|
-
}
|
|
1851
|
-
|
|
1852
1571
|
// src/ide/actions/release.js
|
|
1572
|
+
import { generateKey, pack } from "kintone-plugin-web-signer";
|
|
1853
1573
|
function setupRelease(ctx) {
|
|
1854
1574
|
const { state, log, appId, recordId } = ctx;
|
|
1855
1575
|
async function buildOnly({ prod = ctx.settings.prod } = {}) {
|
|
@@ -1902,7 +1622,8 @@ ${location.hostname} / ${id}` } });
|
|
|
1902
1622
|
}
|
|
1903
1623
|
|
|
1904
1624
|
// src/ide/actions/zip.js
|
|
1905
|
-
import { zipSync as
|
|
1625
|
+
import { zipSync as zipSync3, unzipSync as unzipSync2 } from "fflate";
|
|
1626
|
+
import { unpack } from "kintone-plugin-web-signer";
|
|
1906
1627
|
function setupZip(ctx) {
|
|
1907
1628
|
const { state, log, ui } = ctx;
|
|
1908
1629
|
async function importZipBytes(bytes, name) {
|
|
@@ -1911,7 +1632,7 @@ function setupZip(ctx) {
|
|
|
1911
1632
|
if (unpacked) {
|
|
1912
1633
|
log.info(`${name} はプラグインです(署名 ${unpacked.verified ? "OK" : "NG"}, ID ${unpacked.id})。中身を取り込みます`);
|
|
1913
1634
|
entries = unpacked.contents;
|
|
1914
|
-
} else entries =
|
|
1635
|
+
} else entries = unzipSync2(bytes);
|
|
1915
1636
|
const paths = Object.keys(entries).filter((p) => !p.endsWith("/") && !p.startsWith("__MACOSX/") && !/(^|\/)\.DS_Store$/.test(p) && !/\.ppk$/.test(p));
|
|
1916
1637
|
const mf = paths.filter((p) => /(^|\/)manifest\.json$/.test(p) && !p.includes("node_modules/")).sort((a, b) => a.length - b.length)[0];
|
|
1917
1638
|
const root = mf ? mf.slice(0, -"manifest.json".length) : "";
|
|
@@ -1933,7 +1654,7 @@ function setupZip(ctx) {
|
|
|
1933
1654
|
for (const p of state.sourcePaths()) entries[p] = toBytes(state.files.get(p));
|
|
1934
1655
|
const m = ctx.manifestInfo();
|
|
1935
1656
|
const name = `${m ? safeName(m.name) : "plugin"}-${m ? m.version : "0"}-src.zip`;
|
|
1936
|
-
downloadBlob(
|
|
1657
|
+
downloadBlob(zipSync3(entries, { level: 9 }), name);
|
|
1937
1658
|
log.ok(`ソースを書き出しました: ${name}(node_modules は入れていません)`);
|
|
1938
1659
|
}
|
|
1939
1660
|
for (const target of [ui.editorEl, ui.treeEl]) {
|
|
@@ -2528,6 +2249,8 @@ async function openIDE() {
|
|
|
2528
2249
|
}
|
|
2529
2250
|
|
|
2530
2251
|
// src/index.js
|
|
2252
|
+
import { generateKey as generateKey2, pack as pack2, packFiles, unpack as unpack2, idFromSpki, publicKeyFromPpk } from "kintone-plugin-web-signer";
|
|
2253
|
+
import { browserPlugin as browserPlugin2 } from "esbuild-plugin-browser";
|
|
2531
2254
|
var open2 = () => openIDE().catch((e) => {
|
|
2532
2255
|
console.error(e);
|
|
2533
2256
|
alert("IDEを開けませんでした\n" + e.message);
|
|
@@ -2561,16 +2284,19 @@ function setup(options = {}) {
|
|
|
2561
2284
|
export {
|
|
2562
2285
|
CONFIG,
|
|
2563
2286
|
addToTestApp,
|
|
2287
|
+
browserPlugin2 as browserPlugin,
|
|
2564
2288
|
buildPlugin,
|
|
2565
2289
|
configure,
|
|
2566
2290
|
deployApp,
|
|
2567
|
-
generateKey,
|
|
2291
|
+
generateKey2 as generateKey,
|
|
2568
2292
|
idFromSpki,
|
|
2569
2293
|
install,
|
|
2570
2294
|
openIDE,
|
|
2571
|
-
pack,
|
|
2295
|
+
pack2 as pack,
|
|
2296
|
+
packFiles,
|
|
2297
|
+
publicKeyFromPpk,
|
|
2572
2298
|
readManifest,
|
|
2573
2299
|
setup,
|
|
2574
2300
|
sourceList,
|
|
2575
|
-
unpack
|
|
2301
|
+
unpack2 as unpack
|
|
2576
2302
|
};
|