@rynt/extension-build 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts DELETED
@@ -1,320 +0,0 @@
1
- import { existsSync, readFileSync } from 'node:fs';
2
- import path from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
-
5
- import {
6
- mergeExtensionManifestForDist,
7
- ryntExtensionEmitDistManifestPlugin,
8
- } from './extension-manifest.js';
9
- import { ryntExtensionDevBridgePlugin } from './extension-dev-bridge.js';
10
-
11
- import tailwindcss from '@tailwindcss/vite';
12
- import vuePlugin from '@vitejs/plugin-vue';
13
- import type { ExternalOption, Plugin as RollupPlugin } from 'rollup';
14
- import type { Plugin, PluginOption, UserConfig } from 'vite';
15
-
16
- /**
17
- * Параметры для `ryntExtensionViteConfig`.
18
- * - `root` — абсолютный путь к корню расширения
19
- * - `manifest` — объект манифеста расширения из `vite.config.ts`
20
- */
21
- export interface RyntExtensionViteConfigOptions {
22
- root: string;
23
- manifest: Record<string, unknown>;
24
- }
25
-
26
- export const RYNT_EXTENSION_SHIMMED_SDK_SPECIFIERS = new Set([
27
- '@rynt/sdk',
28
- '@rynt/sdk/extension',
29
- '@rynt/sdk/host',
30
- '@rynt/sdk/session', // Session token access for extensions
31
- ]);
32
-
33
- /**
34
- * Только ядро TipTap с хоста (один экземпляр с MarkdownEditor).
35
- * Пакеты `@tiptap/extension-*` ставит автор расширения и собирает в свой dist.
36
- */
37
- export const RYNT_EXTENSION_HOST_TIPTAP_CORE = '@tiptap/core';
38
-
39
- export const RYNT_EXTENSION_HOST_TIPTAP_SPECIFIERS = new Set([
40
- RYNT_EXTENSION_HOST_TIPTAP_CORE,
41
- ]);
42
-
43
- const RYNT_EXTENSION_BUNDLED_SDK_SPECIFIERS = new Set<string>([]);
44
-
45
- const shimsRoot = path.resolve(
46
- path.dirname(fileURLToPath(import.meta.url)),
47
- '../shims',
48
- );
49
-
50
- function tiptapHostShimFileName(specifier: string): string {
51
- return `${specifier.replace('@tiptap/', 'tiptap-')}.host-shim.js`;
52
- }
53
-
54
- const TIPTAP_CORE_PKG_PATH = /[/\\]@tiptap[/\\]core[/\\]/u;
55
-
56
- function ryntExtensionTiptapCoreHostShimPlugin(shimsAbsoluteRoot: string): Plugin {
57
- const coreShim = path.join(shimsAbsoluteRoot, tiptapHostShimFileName('@tiptap/core'));
58
-
59
- return {
60
- name: 'rynt-extension-tiptap-core-host-shim',
61
- enforce: 'pre',
62
- resolveId(source) {
63
- const clean = source.split('\0')[0]!.split('#')[0]!.split('?')[0]!;
64
- if (clean === '@tiptap/core' || clean.startsWith('@tiptap/core/')) {
65
- return coreShim;
66
- }
67
- const posix = clean.replace(/\\/g, '/');
68
- if (TIPTAP_CORE_PKG_PATH.test(posix)) {
69
- return coreShim;
70
- }
71
- return undefined;
72
- },
73
- };
74
- }
75
-
76
- function ryntExtensionRollupHostShimResolvePlugin(
77
- shimsAbsoluteRoot: string,
78
- ): RollupPlugin {
79
- const specToShimFile: Record<string, string> = {};
80
- for (const spec of RYNT_EXTENSION_SHIMMED_SDK_SPECIFIERS) {
81
- const fileName = `rynt-sdk${spec === '@rynt/sdk' ? '' : spec.replace('@rynt/sdk/', '-')}.host-shim.js`;
82
- specToShimFile[spec] = path.join(shimsAbsoluteRoot, fileName);
83
- }
84
- for (const spec of RYNT_EXTENSION_HOST_TIPTAP_SPECIFIERS) {
85
- specToShimFile[spec] = path.join(
86
- shimsAbsoluteRoot,
87
- tiptapHostShimFileName(spec),
88
- );
89
- }
90
-
91
- return {
92
- name: 'rynt-extension-rollup-host-shim-resolve',
93
- resolveId(id: string) {
94
- const clean = id.split('\0')[0]!.split('#')[0]!.split('?')[0]!;
95
- if (specToShimFile[clean]) {
96
- return specToShimFile[clean];
97
- }
98
- const posix = clean.replace(/\\/g, '/');
99
- if (
100
- specToShimFile['@tiptap/core']
101
- && TIPTAP_CORE_PKG_PATH.test(posix)
102
- ) {
103
- return specToShimFile['@tiptap/core'];
104
- }
105
- return undefined;
106
- },
107
- };
108
- }
109
-
110
- function ryntRollupMergeExternalPlugin(shimsAbsoluteRoot: string): Plugin {
111
- return {
112
- name: 'rynt-extension-merge-external-with-shims',
113
- apply: 'build',
114
- enforce: 'post',
115
- options(optionList) {
116
- const previousExternal = optionList.external;
117
- optionList.external = (
118
- src,
119
- importer,
120
- resolved,
121
- ) => {
122
- const raw = typeof src === 'string' ? src : String(src);
123
- const trimmed = raw.split('\0')[0].split('#')[0].split('?')[0]!;
124
- const posix = trimmed.replace(/\\/g, '/');
125
- const shimsPosix = shimsAbsoluteRoot.replace(/\\/g, '/');
126
-
127
- if (
128
- posix.startsWith(`${shimsPosix}/`)
129
- || posix.includes('/extension-build/shims/')
130
- ) {
131
- return false;
132
- }
133
-
134
- if (
135
- trimmed === 'vue'
136
- || trimmed === 'vue-router'
137
- || RYNT_EXTENSION_SHIMMED_SDK_SPECIFIERS.has(trimmed)
138
- || RYNT_EXTENSION_HOST_TIPTAP_SPECIFIERS.has(trimmed)
139
- || RYNT_EXTENSION_BUNDLED_SDK_SPECIFIERS.has(trimmed)
140
- ) {
141
- return false;
142
- }
143
-
144
- if (
145
- trimmed === '@rynt/sdk'
146
- || (typeof trimmed === 'string' && trimmed.startsWith('@rynt/sdk/'))
147
- ) {
148
- return true;
149
- }
150
-
151
- // @tiptap/extension-* и прочие подпакеты — в бандл расширения (не с хоста).
152
- if (
153
- trimmed.startsWith('@tiptap/')
154
- && trimmed !== RYNT_EXTENSION_HOST_TIPTAP_CORE
155
- ) {
156
- return false;
157
- }
158
-
159
- const prevMarks = coerceExternal(
160
- previousExternal,
161
- trimmed,
162
- importer as string | undefined,
163
- resolved,
164
- );
165
-
166
- return Boolean(prevMarks);
167
- };
168
- },
169
- };
170
- }
171
-
172
- function coerceExternal(
173
- previous: ExternalOption | undefined,
174
- id: string,
175
- importer?: string | undefined,
176
- resolved?: boolean | undefined,
177
- ): boolean | undefined {
178
- if (previous == null) {
179
- return false;
180
- }
181
-
182
- if (typeof previous === 'function') {
183
- return Boolean(previous(id as never, importer as never, resolved ?? false));
184
- }
185
-
186
- if (Array.isArray(previous)) {
187
- return previous.some((entry) =>
188
- typeof entry === 'string' ? entry === id
189
- : entry instanceof RegExp ? entry.test(id)
190
- : false,
191
- );
192
- }
193
-
194
- return previous instanceof RegExp ? previous.test(id) : false;
195
- }
196
-
197
- const RYNT_EXT_TAILWIND_VIRTUAL = '\0rynt-extension:tailwind-entry.css';
198
- const RYNT_EXT_TAILWIND_PUBLIC = 'virtual:rynt-extension/tailwind-entry.css';
199
-
200
- function ryntExtensionVirtualTailwindPlugin(root: string): Plugin {
201
- const entryAbs = path.resolve(root, 'src/index.ts');
202
- const manualTailwindCss = path.join(root, 'src/tailwind.css');
203
-
204
- return {
205
- name: 'rynt-extension-virtual-tailwind-entry',
206
- enforce: 'pre',
207
- resolveId(id) {
208
- if (id === RYNT_EXT_TAILWIND_PUBLIC) return RYNT_EXT_TAILWIND_VIRTUAL;
209
- return undefined;
210
- },
211
- load(id) {
212
- if (id === RYNT_EXT_TAILWIND_VIRTUAL) {
213
- return '@import "tailwindcss";\n';
214
- }
215
- return undefined;
216
- },
217
- transform(code, id) {
218
- if (existsSync(manualTailwindCss)) return null;
219
- if (path.resolve(id) !== entryAbs) return null;
220
- if (/import\s+['"][^'"]*tailwind\.css['"]/u.test(code)) return null;
221
- return `import '${RYNT_EXT_TAILWIND_PUBLIC}';\n${code}`;
222
- },
223
- };
224
- }
225
-
226
- function hostShimAliases(): { find: string | RegExp; replacement: string }[] {
227
- return [
228
- { find: /^vue$/u, replacement: path.join(shimsRoot, 'vue.host-shim.js') },
229
- {
230
- find: /^vue-router$/u,
231
- replacement: path.join(shimsRoot, 'vue-router.host-shim.js'),
232
- },
233
- {
234
- find: /^@rynt\/sdk$/u,
235
- replacement: path.join(shimsRoot, 'rynt-sdk.host-shim.js'),
236
- },
237
- {
238
- find: /^@rynt\/sdk\/extension$/u,
239
- replacement: path.join(shimsRoot, 'rynt-sdk-extension.host-shim.js'),
240
- },
241
- {
242
- find: /^@rynt\/sdk\/host$/u,
243
- replacement: path.join(shimsRoot, 'rynt-sdk-host.host-shim.js'),
244
- },
245
- {
246
- find: /^@tiptap\/core(\/.*)?$/u,
247
- replacement: path.join(shimsRoot, tiptapHostShimFileName('@tiptap/core')),
248
- },
249
- ];
250
- }
251
-
252
- export function ryntExtensionViteConfig(
253
- options: RyntExtensionViteConfigOptions,
254
- ): UserConfig {
255
- const { root, manifest } = options;
256
- const merged = mergeExtensionManifestForDist(root, manifest);
257
- const manifestId =
258
- typeof merged.id === 'string' && merged.id.length > 0 ? merged.id : null;
259
- if (!manifestId) {
260
- console.warn(
261
- '[rynt/extension-build] Не удалось определить id (manifest.id и package.json name пусты); registry writes will fall under "rynt" (host).',
262
- );
263
- }
264
-
265
- const resolveAliases = [
266
- ...hostShimAliases(),
267
- { find: /^@\//u, replacement: `${path.join(root, 'src')}/` },
268
- ];
269
-
270
- return {
271
- plugins: [
272
- ryntExtensionTiptapCoreHostShimPlugin(shimsRoot),
273
- ryntExtensionVirtualTailwindPlugin(root),
274
- tailwindcss(),
275
- vuePlugin(),
276
- ryntRollupMergeExternalPlugin(shimsRoot),
277
- ryntExtensionDevBridgePlugin({ root, manifestFromVite: manifest }),
278
- ryntExtensionEmitDistManifestPlugin({ root, manifestFromVite: manifest }),
279
- ] as PluginOption[],
280
- resolve: {
281
- alias: resolveAliases,
282
- dedupe: ['@tiptap/core'],
283
- },
284
- define: {
285
- __RYNT_EXTENSION_ID__: JSON.stringify(manifestId ?? 'rynt'),
286
- },
287
- build: {
288
- lib: {
289
- entry: path.join(root, 'src/index.ts'),
290
- name: 'rynt-extension',
291
- formats: ['es'],
292
- fileName: 'index',
293
- },
294
- outDir: path.join(root, 'dist'),
295
- emptyOutDir: true,
296
- rollupOptions: {
297
- plugins: [ryntExtensionRollupHostShimResolvePlugin(shimsRoot)],
298
- },
299
- },
300
- };
301
- }
302
-
303
- export {
304
- EXTENSION_ICON_DIST_PNG,
305
- EXTENSION_ICON_MAX_SIZE,
306
- applyExtensionIconToManifest,
307
- isBundledExtensionIconRef,
308
- isLocalIconSource,
309
- isRemoteOrDataIcon,
310
- processExtensionIconForDist,
311
- } from './extension-icon.js';
312
- export {
313
- mergeExtensionManifestForDist,
314
- ryntExtensionEmitDistManifestPlugin,
315
- } from './extension-manifest.js';
316
- export {
317
- RYNT_LAUNCHER_DEV_HUB_DEFAULT,
318
- isDevBridgeActive,
319
- ryntExtensionDevBridgePlugin,
320
- } from './extension-dev-bridge.js';
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "NodeNext",
5
- "moduleResolution": "NodeNext",
6
- "declaration": true,
7
- "declarationMap": true,
8
- "outDir": "./dist",
9
- "rootDir": "./src",
10
- "strict": true,
11
- "skipLibCheck": true,
12
- "esModuleInterop": true,
13
- "resolveJsonModule": true
14
- },
15
- "include": ["src/**/*.ts"]
16
- }