@ynput/ayon-addon-dev 0.0.0-stage → 0.1.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/AGENTS.md +139 -0
- package/LICENSE +105 -0
- package/dist/browse.d.ts +59 -0
- package/dist/browse.js +156 -0
- package/dist/check.d.ts +30 -0
- package/dist/check.js +117 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +249 -0
- package/dist/eslint.d.ts +13 -0
- package/dist/eslint.js +47 -0
- package/dist/project.d.ts +28 -0
- package/dist/project.js +97 -0
- package/dist/rest.d.ts +47 -0
- package/dist/rest.js +181 -0
- package/dist/shell/index.js +1635 -0
- package/dist/shell/style.css +416 -0
- package/dist/standalone.d.ts +12 -0
- package/dist/standalone.js +176 -0
- package/dist/vite.d.ts +31 -0
- package/dist/vite.js +147 -0
- package/package.json +63 -4
- package/README.md +0 -3
package/dist/vite.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// ayonAddon(): the Vite setup of an AYON addon frontend in one plugin.
|
|
2
|
+
// build: module federation (remote `name`, ./manifest exposed, every package AYON provides
|
|
3
|
+
// shared, @ynput/ayon-addon with import: false), output in dist/modules/<name>
|
|
4
|
+
// `ayon-addon dev --ayon`: the same build, watched, plus /ayon-addon.json for AYON's dev override
|
|
5
|
+
// `ayon-addon dev`: the Vite dev server with the dev shell (standalone.ts)
|
|
6
|
+
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import { findPackageDir, importFromProject, installedVersion, readAddonProject } from './project.js';
|
|
9
|
+
import { standalonePlugin } from './standalone.js';
|
|
10
|
+
// packages AYON provides to addons (vite federation config and src/remote/hostSharedModules.ts)
|
|
11
|
+
export const HOST_PACKAGES = [
|
|
12
|
+
'react',
|
|
13
|
+
'react-dom',
|
|
14
|
+
'styled-components',
|
|
15
|
+
'@ynput/ayon-react-components',
|
|
16
|
+
'@reduxjs/toolkit',
|
|
17
|
+
'react-redux',
|
|
18
|
+
'react-router',
|
|
19
|
+
'react-router-dom',
|
|
20
|
+
'react-toastify',
|
|
21
|
+
];
|
|
22
|
+
export const SHARED_PACKAGE = '@ynput/ayon-frontend-shared';
|
|
23
|
+
export const ADDON_API = '@ynput/ayon-addon';
|
|
24
|
+
const readJson = (file) => JSON.parse(readFileSync(file, 'utf8'));
|
|
25
|
+
// the build's entry when the addon has no index.html: AYON loads remoteEntry.js, nothing else
|
|
26
|
+
const BUILD_ENTRY = '\0ayon-addon-build-entry';
|
|
27
|
+
const buildShared = (root, extra = []) => {
|
|
28
|
+
const pkg = readJson(path.join(root, 'package.json'));
|
|
29
|
+
const declared = { ...pkg.devDependencies, ...pkg.dependencies };
|
|
30
|
+
const range = (name) => {
|
|
31
|
+
const declaredRange = declared[name];
|
|
32
|
+
if (declaredRange && /^[\^~><=\d]/.test(declaredRange))
|
|
33
|
+
return declaredRange;
|
|
34
|
+
const version = installedVersion(root, name);
|
|
35
|
+
return version ? `^${version}` : false;
|
|
36
|
+
};
|
|
37
|
+
const shared = {};
|
|
38
|
+
for (const name of [...HOST_PACKAGES, ...extra]) {
|
|
39
|
+
if (!installedVersion(root, name))
|
|
40
|
+
continue;
|
|
41
|
+
shared[name] = { singleton: true, requiredVersion: range(name) };
|
|
42
|
+
}
|
|
43
|
+
// every entry of @ynput/ayon-frontend-shared: an entry left out would bring its own api and contexts
|
|
44
|
+
const sharedDir = findPackageDir(root, SHARED_PACKAGE);
|
|
45
|
+
if (sharedDir) {
|
|
46
|
+
const exportsMap = readJson(path.join(sharedDir, 'package.json')).exports;
|
|
47
|
+
for (const [subpath, entry] of Object.entries(exportsMap)) {
|
|
48
|
+
// skip entries the published package lists but doesn't ship
|
|
49
|
+
if (!entry.import || !existsSync(path.join(sharedDir, entry.import)))
|
|
50
|
+
continue;
|
|
51
|
+
shared[path.posix.join(SHARED_PACKAGE, subpath)] = {
|
|
52
|
+
singleton: true,
|
|
53
|
+
requiredVersion: range(SHARED_PACKAGE),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// always AYON's own copy: the addon bundles none, so it can't end up with a second registry
|
|
58
|
+
const addonApiVersion = installedVersion(root, ADDON_API);
|
|
59
|
+
if (!addonApiVersion)
|
|
60
|
+
throw new Error(`${ADDON_API} is not installed in ${root}`);
|
|
61
|
+
shared[ADDON_API] = { import: false, singleton: true, requiredVersion: `^${addonApiVersion}` };
|
|
62
|
+
return shared;
|
|
63
|
+
};
|
|
64
|
+
/** The Vite plugins of an AYON addon frontend. Use with @vitejs/plugin-react. */
|
|
65
|
+
export const ayonAddon = async (options) => {
|
|
66
|
+
const root = process.cwd();
|
|
67
|
+
const project = readAddonProject(root);
|
|
68
|
+
const manifest = options.manifest || './src/manifest.ts';
|
|
69
|
+
const exposes = { './manifest': manifest, ...options.exposes };
|
|
70
|
+
const outDir = path.join('dist', 'modules', options.name);
|
|
71
|
+
const { federation } = await importFromProject(root, '@module-federation/vite');
|
|
72
|
+
const federationPlugins = [].concat(federation({
|
|
73
|
+
name: options.name,
|
|
74
|
+
filename: 'remoteEntry.js',
|
|
75
|
+
exposes,
|
|
76
|
+
remotes: {},
|
|
77
|
+
// AYON loads the modules at runtime, it needs no federation type declarations
|
|
78
|
+
dts: false,
|
|
79
|
+
// use what AYON already loaded (its store, api and contexts), even when this addon was
|
|
80
|
+
// built against a newer version
|
|
81
|
+
shareStrategy: 'loaded-first',
|
|
82
|
+
shared: buildShared(root, options.shared),
|
|
83
|
+
}));
|
|
84
|
+
// federation only makes sense for the build AYON loads; the dev server runs on its own
|
|
85
|
+
federationPlugins.forEach((plugin) => (plugin.apply = plugin.apply || 'build'));
|
|
86
|
+
const config = {
|
|
87
|
+
name: 'ayon-addon',
|
|
88
|
+
// the CLI reads the options from the addon's vite.config.ts (generate-rest)
|
|
89
|
+
api: { options },
|
|
90
|
+
config(_config, { command, mode }) {
|
|
91
|
+
return {
|
|
92
|
+
base: '',
|
|
93
|
+
resolve: {
|
|
94
|
+
// a linked SDK must use the addon's React, router and store, never the checkout's
|
|
95
|
+
dedupe: [...HOST_PACKAGES, SHARED_PACKAGE, ADDON_API],
|
|
96
|
+
},
|
|
97
|
+
build: command === 'build'
|
|
98
|
+
? {
|
|
99
|
+
target: 'chrome89',
|
|
100
|
+
outDir,
|
|
101
|
+
emptyOutDir: true,
|
|
102
|
+
cssCodeSplit: false,
|
|
103
|
+
minify: mode !== 'development',
|
|
104
|
+
sourcemap: mode === 'development',
|
|
105
|
+
...(existsSync(path.join(root, 'index.html'))
|
|
106
|
+
? {}
|
|
107
|
+
: { rollupOptions: { input: { 'ayon-addon': BUILD_ENTRY } } }),
|
|
108
|
+
}
|
|
109
|
+
: undefined,
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
resolveId(id) {
|
|
113
|
+
if (id === BUILD_ENTRY)
|
|
114
|
+
return id;
|
|
115
|
+
},
|
|
116
|
+
load(id) {
|
|
117
|
+
if (id === BUILD_ENTRY)
|
|
118
|
+
return 'export {}';
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
// `ayon-addon dev --ayon` sets AYON_ADDON_DEV: after each rebuild, tell AYON's dev override about it
|
|
122
|
+
const devInfo = {
|
|
123
|
+
name: 'ayon-addon:dev-info',
|
|
124
|
+
apply: 'build',
|
|
125
|
+
writeBundle(outputOptions) {
|
|
126
|
+
if (process.env.AYON_ADDON_DEV !== '1' || !outputOptions.dir)
|
|
127
|
+
return;
|
|
128
|
+
const info = {
|
|
129
|
+
name: project.name,
|
|
130
|
+
version: project.version,
|
|
131
|
+
remote: options.name,
|
|
132
|
+
modules: Object.keys(exposes).map((key) => key.replace(/^\.\//, '')),
|
|
133
|
+
buildId: Date.now().toString(36),
|
|
134
|
+
};
|
|
135
|
+
writeFileSync(path.join(outputOptions.dir, 'ayon-addon.json'), JSON.stringify(info, null, 2));
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
const standalone = standalonePlugin({
|
|
139
|
+
root,
|
|
140
|
+
project,
|
|
141
|
+
remote: options.name,
|
|
142
|
+
manifest,
|
|
143
|
+
fixtures: options.fixtures || 'dev/fixtures',
|
|
144
|
+
});
|
|
145
|
+
return [...federationPlugins, config, devInfo, standalone];
|
|
146
|
+
};
|
|
147
|
+
export default ayonAddon;
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ynput/ayon-addon-dev",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Dev tooling for AYON addon frontends: Vite plugin, dev server, CLI, lint preset",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/ynput/ayon-frontend.git",
|
|
8
|
+
"directory": "addon-dev"
|
|
9
|
+
},
|
|
10
|
+
"license": "FSL-1.1-ALv2",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"bin": {
|
|
13
|
+
"ayon-addon": "./dist/cli.js"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
"./vite": {
|
|
17
|
+
"types": "./dist/vite.d.ts",
|
|
18
|
+
"import": "./dist/vite.js"
|
|
19
|
+
},
|
|
20
|
+
"./eslint": {
|
|
21
|
+
"types": "./dist/eslint.d.ts",
|
|
22
|
+
"import": "./dist/eslint.js"
|
|
23
|
+
},
|
|
24
|
+
"./AGENTS.md": "./AGENTS.md",
|
|
25
|
+
"./shell": "./dist/shell/index.js",
|
|
26
|
+
"./shell/style.css": "./dist/shell/style.css"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"AGENTS.md"
|
|
31
|
+
],
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc -p tsconfig.json && chmod +x dist/cli.js && vite build --config shell/vite.config.ts",
|
|
37
|
+
"typecheck:shell": "tsc -p shell/tsconfig.json"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@tanstack/react-table": "^8.21.3"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@module-federation/vite": ">=1.14",
|
|
44
|
+
"@ynput/ayon-addon": "^0.1.1",
|
|
45
|
+
"vite": ">=6",
|
|
46
|
+
"@ynput/ayon-frontend-shared": ">=0.7.5",
|
|
47
|
+
"@ynput/ayon-react-components": "^1.24.0",
|
|
48
|
+
"primereact": ">=9",
|
|
49
|
+
"react": ">=18",
|
|
50
|
+
"react-dom": ">=18",
|
|
51
|
+
"react-redux": ">=9",
|
|
52
|
+
"react-router-dom": ">=7",
|
|
53
|
+
"react-toastify": ">=9",
|
|
54
|
+
"playwright": ">=1.40",
|
|
55
|
+
"@rtk-query/codegen-openapi": ">=2"
|
|
56
|
+
},
|
|
57
|
+
"peerDependenciesMeta": {
|
|
58
|
+
"playwright": {
|
|
59
|
+
"optional": true
|
|
60
|
+
},
|
|
61
|
+
"@rtk-query/codegen-openapi": {
|
|
62
|
+
"optional": true
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
package/README.md
DELETED