@strapi/typescript-utils 0.0.0-experimental.6340da17068c3bed7fb006e7bcc554c71129e282 → 0.0.0-experimental.63624e21eb5b0713345a0cf2f68f1c40eab427bc
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/dist/compile.d.ts +5 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +12 -0
- package/dist/compile.js.map +1 -0
- package/dist/compile.mjs +10 -0
- package/dist/compile.mjs.map +1 -0
- package/dist/compilers/basic.d.ts +11 -0
- package/dist/compilers/basic.d.ts.map +1 -0
- package/dist/compilers/basic.js +58 -0
- package/dist/compilers/basic.js.map +1 -0
- package/dist/compilers/basic.mjs +36 -0
- package/dist/compilers/basic.mjs.map +1 -0
- package/dist/compilers/index.d.ts +3 -0
- package/dist/compilers/index.d.ts.map +1 -0
- package/dist/compilers/index.js +8 -0
- package/dist/compilers/index.js.map +1 -0
- package/dist/compilers/index.mjs +3 -0
- package/dist/compilers/index.mjs.map +1 -0
- package/dist/generators/common/compare.d.ts +14 -0
- package/dist/generators/common/compare.d.ts.map +1 -0
- package/dist/generators/common/compare.js +25 -0
- package/dist/generators/common/compare.js.map +1 -0
- package/dist/generators/common/compare.mjs +22 -0
- package/dist/generators/common/compare.mjs.map +1 -0
- package/dist/generators/common/imports.d.ts +5 -0
- package/dist/generators/common/imports.d.ts.map +1 -0
- package/dist/generators/common/imports.js +42 -0
- package/dist/generators/common/imports.js.map +1 -0
- package/dist/generators/common/imports.mjs +19 -0
- package/dist/generators/common/imports.mjs.map +1 -0
- package/dist/generators/common/index.d.ts +4 -0
- package/dist/generators/common/index.d.ts.map +1 -0
- package/dist/generators/common/interface-names.d.ts +16 -0
- package/dist/generators/common/interface-names.d.ts.map +1 -0
- package/dist/generators/common/interface-names.js +54 -0
- package/dist/generators/common/interface-names.js.map +1 -0
- package/dist/generators/common/interface-names.mjs +52 -0
- package/dist/generators/common/interface-names.mjs.map +1 -0
- package/dist/generators/common/models/attributes.d.ts +38 -0
- package/dist/generators/common/models/attributes.d.ts.map +1 -0
- package/dist/generators/common/models/attributes.js +205 -0
- package/dist/generators/common/models/attributes.js.map +1 -0
- package/dist/generators/common/models/attributes.mjs +176 -0
- package/dist/generators/common/models/attributes.mjs.map +1 -0
- package/dist/generators/common/models/index.d.ts +7 -0
- package/dist/generators/common/models/index.d.ts.map +1 -0
- package/dist/generators/common/models/mappers.d.ts +9 -0
- package/dist/generators/common/models/mappers.d.ts.map +1 -0
- package/dist/generators/common/models/mappers.js +227 -0
- package/dist/generators/common/models/mappers.js.map +1 -0
- package/dist/generators/common/models/mappers.mjs +202 -0
- package/dist/generators/common/models/mappers.mjs.map +1 -0
- package/dist/generators/common/models/schema.d.ts +8 -0
- package/dist/generators/common/models/schema.d.ts.map +1 -0
- package/dist/generators/common/models/schema.js +78 -0
- package/dist/generators/common/models/schema.js.map +1 -0
- package/dist/generators/common/models/schema.mjs +56 -0
- package/dist/generators/common/models/schema.mjs.map +1 -0
- package/dist/generators/common/models/utils.d.ts +57 -0
- package/dist/generators/common/models/utils.d.ts.map +1 -0
- package/dist/generators/common/models/utils.js +110 -0
- package/dist/generators/common/models/utils.js.map +1 -0
- package/dist/generators/common/models/utils.mjs +82 -0
- package/dist/generators/common/models/utils.mjs.map +1 -0
- package/dist/generators/common/sources.d.ts +133 -0
- package/dist/generators/common/sources.d.ts.map +1 -0
- package/dist/generators/common/sources.js +354 -0
- package/dist/generators/common/sources.js.map +1 -0
- package/dist/generators/common/sources.mjs +318 -0
- package/dist/generators/common/sources.mjs.map +1 -0
- package/dist/generators/components/index.d.ts +9 -0
- package/dist/generators/components/index.d.ts.map +1 -0
- package/dist/generators/components/index.js +84 -0
- package/dist/generators/components/index.js.map +1 -0
- package/dist/generators/components/index.mjs +62 -0
- package/dist/generators/components/index.mjs.map +1 -0
- package/dist/generators/constants.d.ts +3 -0
- package/dist/generators/constants.d.ts.map +1 -0
- package/dist/generators/constants.js +8 -0
- package/dist/generators/constants.js.map +1 -0
- package/dist/generators/constants.mjs +5 -0
- package/dist/generators/constants.mjs.map +1 -0
- package/dist/generators/content-types/index.d.ts +9 -0
- package/dist/generators/content-types/index.d.ts.map +1 -0
- package/dist/generators/content-types/index.js +84 -0
- package/dist/generators/content-types/index.js.map +1 -0
- package/dist/generators/content-types/index.mjs +62 -0
- package/dist/generators/content-types/index.mjs.map +1 -0
- package/dist/generators/controllers/index.d.ts +35 -0
- package/dist/generators/controllers/index.d.ts.map +1 -0
- package/dist/generators/controllers/index.js +88 -0
- package/dist/generators/controllers/index.js.map +1 -0
- package/dist/generators/controllers/index.mjs +86 -0
- package/dist/generators/controllers/index.mjs.map +1 -0
- package/dist/generators/index.d.ts +31 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +150 -0
- package/dist/generators/index.js.map +1 -0
- package/dist/generators/index.mjs +142 -0
- package/dist/generators/index.mjs.map +1 -0
- package/dist/generators/middlewares/index.d.ts +30 -0
- package/dist/generators/middlewares/index.d.ts.map +1 -0
- package/dist/generators/middlewares/index.js +163 -0
- package/dist/generators/middlewares/index.js.map +1 -0
- package/dist/generators/middlewares/index.mjs +141 -0
- package/dist/generators/middlewares/index.mjs.map +1 -0
- package/dist/generators/plugins/index.d.ts +9 -0
- package/dist/generators/plugins/index.d.ts.map +1 -0
- package/dist/generators/plugins/index.js +225 -0
- package/dist/generators/plugins/index.js.map +1 -0
- package/dist/generators/plugins/index.mjs +200 -0
- package/dist/generators/plugins/index.mjs.map +1 -0
- package/dist/generators/policies/index.d.ts +29 -0
- package/dist/generators/policies/index.d.ts.map +1 -0
- package/dist/generators/policies/index.js +135 -0
- package/dist/generators/policies/index.js.map +1 -0
- package/dist/generators/policies/index.mjs +113 -0
- package/dist/generators/policies/index.mjs.map +1 -0
- package/dist/generators/services/index.d.ts +35 -0
- package/dist/generators/services/index.d.ts.map +1 -0
- package/dist/generators/services/index.js +87 -0
- package/dist/generators/services/index.js.map +1 -0
- package/dist/generators/services/index.mjs +85 -0
- package/dist/generators/services/index.mjs.map +1 -0
- package/dist/generators/strict/index.d.ts +13 -0
- package/dist/generators/strict/index.d.ts.map +1 -0
- package/dist/generators/strict/index.js +24 -0
- package/dist/generators/strict/index.js.map +1 -0
- package/dist/generators/strict/index.mjs +22 -0
- package/dist/generators/strict/index.mjs.map +1 -0
- package/dist/generators/utils.d.ts +68 -0
- package/dist/generators/utils.d.ts.map +1 -0
- package/dist/generators/utils.js +201 -0
- package/dist/generators/utils.js.map +1 -0
- package/dist/generators/utils.mjs +166 -0
- package/dist/generators/utils.mjs.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +14 -0
- package/dist/index.mjs.map +1 -0
- package/dist/utils/format-host.d.ts +3 -0
- package/dist/utils/format-host.d.ts.map +1 -0
- package/dist/utils/format-host.js +33 -0
- package/dist/utils/format-host.js.map +1 -0
- package/dist/utils/format-host.mjs +11 -0
- package/dist/utils/format-host.mjs.map +1 -0
- package/dist/utils/get-config-path.d.ts +10 -0
- package/dist/utils/get-config-path.d.ts.map +1 -0
- package/dist/utils/get-config-path.js +43 -0
- package/dist/utils/get-config-path.js.map +1 -0
- package/dist/utils/get-config-path.mjs +18 -0
- package/dist/utils/get-config-path.mjs.map +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/is-using-typescript-sync.d.ts +5 -0
- package/dist/utils/is-using-typescript-sync.d.ts.map +1 -0
- package/dist/utils/is-using-typescript-sync.js +20 -0
- package/dist/utils/is-using-typescript-sync.js.map +1 -0
- package/dist/utils/is-using-typescript-sync.mjs +14 -0
- package/dist/utils/is-using-typescript-sync.mjs.map +1 -0
- package/dist/utils/is-using-typescript.d.ts +5 -0
- package/dist/utils/is-using-typescript.d.ts.map +1 -0
- package/dist/utils/is-using-typescript.js +20 -0
- package/dist/utils/is-using-typescript.js.map +1 -0
- package/dist/utils/is-using-typescript.mjs +14 -0
- package/dist/utils/is-using-typescript.mjs.map +1 -0
- package/dist/utils/report-diagnostics.d.ts +6 -0
- package/dist/utils/report-diagnostics.d.ts.map +1 -0
- package/dist/utils/report-diagnostics.js +37 -0
- package/dist/utils/report-diagnostics.js.map +1 -0
- package/dist/utils/report-diagnostics.mjs +15 -0
- package/dist/utils/report-diagnostics.mjs.map +1 -0
- package/dist/utils/resolve-config-options.d.ts +12 -0
- package/dist/utils/resolve-config-options.d.ts.map +1 -0
- package/dist/utils/resolve-config-options.js +39 -0
- package/dist/utils/resolve-config-options.js.map +1 -0
- package/dist/utils/resolve-config-options.mjs +17 -0
- package/dist/utils/resolve-config-options.mjs.map +1 -0
- package/dist/utils/resolve-outdir-sync.d.ts +5 -0
- package/dist/utils/resolve-outdir-sync.d.ts.map +1 -0
- package/dist/utils/resolve-outdir-sync.js +19 -0
- package/dist/utils/resolve-outdir-sync.js.map +1 -0
- package/dist/utils/resolve-outdir-sync.mjs +13 -0
- package/dist/utils/resolve-outdir-sync.mjs.map +1 -0
- package/dist/utils/resolve-outdir.d.ts +5 -0
- package/dist/utils/resolve-outdir.d.ts.map +1 -0
- package/dist/utils/resolve-outdir.js +19 -0
- package/dist/utils/resolve-outdir.js.map +1 -0
- package/dist/utils/resolve-outdir.mjs +13 -0
- package/dist/utils/resolve-outdir.mjs.map +1 -0
- package/package.json +27 -12
- package/.eslintrc.cjs +0 -16
- package/index.d.ts +0 -5
- package/jest.config.js +0 -6
- package/lib/__tests__/generators/schemas/attributes.test.js +0 -903
- package/lib/__tests__/generators/schemas/imports.test.js +0 -56
- package/lib/__tests__/generators/schemas/utils.test.js +0 -314
- package/lib/compile.js +0 -10
- package/lib/compilers/basic.js +0 -50
- package/lib/compilers/index.js +0 -7
- package/lib/generators/common/imports.js +0 -34
- package/lib/generators/common/index.js +0 -9
- package/lib/generators/common/models/attributes.js +0 -198
- package/lib/generators/common/models/index.js +0 -15
- package/lib/generators/common/models/mappers.js +0 -144
- package/lib/generators/common/models/schema.js +0 -93
- package/lib/generators/common/models/utils.js +0 -178
- package/lib/generators/components/index.js +0 -74
- package/lib/generators/constants.js +0 -6
- package/lib/generators/content-types/index.js +0 -74
- package/lib/generators/index.js +0 -122
- package/lib/generators/utils.js +0 -216
- package/lib/index.js +0 -13
- package/lib/utils/format-host.js +0 -15
- package/lib/utils/get-config-path.js +0 -29
- package/lib/utils/index.js +0 -21
- package/lib/utils/is-using-typescript-sync.js +0 -19
- package/lib/utils/is-using-typescript.js +0 -17
- package/lib/utils/report-diagnostics.js +0 -19
- package/lib/utils/resolve-config-options.js +0 -23
- package/lib/utils/resolve-outdir-sync.js +0 -18
- package/lib/utils/resolve-outdir.js +0 -18
- package/lint-staged.config.mjs +0 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { GeneratorOptions } from '../utils';
|
|
2
|
+
/** Imports the server declarations of enabled, loaded plugins without enabling strict typing. */
|
|
3
|
+
export declare const generatePluginDefinitions: (options: GeneratorOptions) => Promise<{
|
|
4
|
+
output: string;
|
|
5
|
+
stats: {
|
|
6
|
+
plugins: number;
|
|
7
|
+
};
|
|
8
|
+
}>;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/generators/plugins/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AA6JjD,iGAAiG;AACjG,eAAO,MAAM,yBAAyB,GAAU,SAAS,gBAAgB;;;;;EA6HxE,CAAC"}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('node:path');
|
|
4
|
+
var ts = require('typescript');
|
|
5
|
+
var utils = require('../utils.js');
|
|
6
|
+
var compare = require('../common/compare.js');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
function _interopNamespace(e) {
|
|
11
|
+
if (e && e.__esModule) return e;
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n.default = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
29
|
+
var ts__namespace = /*#__PURE__*/_interopNamespace(ts);
|
|
30
|
+
|
|
31
|
+
const declarationExtensions = new Set([
|
|
32
|
+
ts__namespace.Extension.Dts,
|
|
33
|
+
ts__namespace.Extension.Dmts,
|
|
34
|
+
ts__namespace.Extension.Dcts
|
|
35
|
+
]);
|
|
36
|
+
const realpath = (filename)=>ts__namespace.sys.realpath?.(filename) ?? path__default.default.resolve(filename);
|
|
37
|
+
const readCompilerOptions = (appDir)=>{
|
|
38
|
+
const configPath = path__default.default.join(appDir, 'tsconfig.json');
|
|
39
|
+
if (ts__namespace.sys.fileExists(configPath) === false) {
|
|
40
|
+
return {
|
|
41
|
+
module: ts__namespace.ModuleKind.CommonJS,
|
|
42
|
+
moduleResolution: ts__namespace.ModuleResolutionKind.Node10
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const config = ts__namespace.readConfigFile(configPath, ts__namespace.sys.readFile);
|
|
46
|
+
if (config.error !== undefined) {
|
|
47
|
+
throw new Error(ts__namespace.flattenDiagnosticMessageText(config.error.messageText, '\n'));
|
|
48
|
+
}
|
|
49
|
+
const parsed = ts__namespace.parseJsonConfigFileContent(config.config, ts__namespace.sys, appDir, undefined, configPath);
|
|
50
|
+
// Generation may run before any input files exist. Invalid compiler options still matter.
|
|
51
|
+
const errors = parsed.errors.filter((error)=>error.code !== 18002 && error.code !== 18003);
|
|
52
|
+
if (errors.length > 0) {
|
|
53
|
+
throw new Error(errors.map((error)=>ts__namespace.flattenDiagnosticMessageText(error.messageText, '\n')).join('\n'));
|
|
54
|
+
}
|
|
55
|
+
return parsed.options;
|
|
56
|
+
};
|
|
57
|
+
const resolveDeclaration = (specifier, containingFile, compilerOptions, pluginDirectory)=>{
|
|
58
|
+
const mode = ts__namespace.getImpliedNodeFormatForFile(containingFile, undefined, ts__namespace.sys, compilerOptions);
|
|
59
|
+
const resolved = ts__namespace.resolveModuleName(specifier, containingFile, compilerOptions, ts__namespace.sys, undefined, undefined, mode).resolvedModule;
|
|
60
|
+
if (resolved === undefined || declarationExtensions.has(resolved.extension) === false) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
const filename = path__default.default.resolve(resolved.resolvedFileName);
|
|
64
|
+
const relative = path__default.default.relative(realpath(pluginDirectory), realpath(filename));
|
|
65
|
+
// An alias or a same-named package elsewhere must not import another plugin's contract.
|
|
66
|
+
if (relative.startsWith(`..${path__default.default.sep}`) || path__default.default.isAbsolute(relative)) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
return filename;
|
|
70
|
+
};
|
|
71
|
+
const packageNameOf = (specifier)=>{
|
|
72
|
+
const segments = specifier.split('/');
|
|
73
|
+
return (specifier.startsWith('@') ? segments.slice(0, 2) : segments.slice(0, 1)).join('/');
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Names of the packages `@strapi/strapi/strict-types` already loads. Their store path under a
|
|
77
|
+
* strict package manager layout is machine-local, so they must not be imported again.
|
|
78
|
+
*/ const readBundledPackages = (containingFile, compilerOptionsList)=>{
|
|
79
|
+
for (const compilerOptions of compilerOptionsList){
|
|
80
|
+
const mode = ts__namespace.getImpliedNodeFormatForFile(containingFile, undefined, ts__namespace.sys, compilerOptions);
|
|
81
|
+
const resolved = ts__namespace.resolveModuleName('@strapi/strapi/strict-types', containingFile, compilerOptions, ts__namespace.sys, undefined, undefined, mode).resolvedModule;
|
|
82
|
+
if (resolved === undefined) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const contents = ts__namespace.sys.readFile(resolved.resolvedFileName);
|
|
86
|
+
if (contents === undefined) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const { typeReferenceDirectives } = ts__namespace.preProcessFile(contents, false);
|
|
90
|
+
return new Set(typeReferenceDirectives.map(({ fileName })=>packageNameOf(fileName)));
|
|
91
|
+
}
|
|
92
|
+
return new Set();
|
|
93
|
+
};
|
|
94
|
+
const augmentsSettings = (node, namespaces = [])=>{
|
|
95
|
+
const currentNamespaces = ts__namespace.isModuleDeclaration(node) ? [
|
|
96
|
+
...namespaces,
|
|
97
|
+
node.name.text
|
|
98
|
+
] : namespaces;
|
|
99
|
+
if (ts__namespace.isInterfaceDeclaration(node) && node.name.text === 'Settings' && currentNamespaces.slice(-2).join('.') === 'Strapi.Registries') {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
return ts__namespace.forEachChild(node, (child)=>augmentsSettings(child, currentNamespaces)) === true;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Why a plugin's server declaration opts its consumers in to strict types, if it does. Only the
|
|
106
|
+
* entry file is read: a leaking import deeper in the plugin's declarations is not reported.
|
|
107
|
+
*/ const readStrictOptIn = (declaration)=>{
|
|
108
|
+
const contents = ts__namespace.sys.readFile(declaration);
|
|
109
|
+
if (contents === undefined) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
const { importedFiles, typeReferenceDirectives } = ts__namespace.preProcessFile(contents, true);
|
|
113
|
+
const references = [
|
|
114
|
+
...importedFiles,
|
|
115
|
+
...typeReferenceDirectives
|
|
116
|
+
];
|
|
117
|
+
if (references.some(({ fileName })=>fileName === '@strapi/strapi/strict-types') === true) {
|
|
118
|
+
return 'imports @strapi/strapi/strict-types';
|
|
119
|
+
}
|
|
120
|
+
const source = ts__namespace.createSourceFile(declaration, contents, ts__namespace.ScriptTarget.Latest);
|
|
121
|
+
return augmentsSettings(source) === true ? 'augments Strapi.Registries.Settings' : undefined;
|
|
122
|
+
};
|
|
123
|
+
const relativeImport = (filename, containingFile)=>{
|
|
124
|
+
const relative = path__default.default.relative(path__default.default.dirname(containingFile), filename).split(path__default.default.sep).join('/');
|
|
125
|
+
return relative.startsWith('../') ? relative : `./${relative}`;
|
|
126
|
+
};
|
|
127
|
+
/** Imports the server declarations of enabled, loaded plugins without enabling strict typing. */ const generatePluginDefinitions = async (options)=>{
|
|
128
|
+
const { strapi } = options;
|
|
129
|
+
const appDir = options.appDir ?? process.cwd();
|
|
130
|
+
const containingFile = path__default.default.join(options.pwd ?? appDir, 'plugins.d.ts');
|
|
131
|
+
// Preserve the installed path in generated imports, including workspace and pnpm links.
|
|
132
|
+
// Canonical paths are used only to identify the plugin and deduplicate declarations.
|
|
133
|
+
const compilerOptions = {
|
|
134
|
+
...readCompilerOptions(appDir),
|
|
135
|
+
preserveSymlinks: true
|
|
136
|
+
};
|
|
137
|
+
const modernOptions = {
|
|
138
|
+
...compilerOptions,
|
|
139
|
+
module: ts__namespace.ModuleKind.NodeNext,
|
|
140
|
+
moduleResolution: ts__namespace.ModuleResolutionKind.NodeNext
|
|
141
|
+
};
|
|
142
|
+
const enabledPlugins = strapi.config.get('enabledPlugins', {});
|
|
143
|
+
const dependencies = strapi.config.get('info.dependencies', {});
|
|
144
|
+
const importsByDeclaration = new Map();
|
|
145
|
+
const bundledPackages = readBundledPackages(containingFile, [
|
|
146
|
+
compilerOptions,
|
|
147
|
+
modernOptions
|
|
148
|
+
]);
|
|
149
|
+
for (const [name, plugin] of Object.entries(enabledPlugins).sort(([a], [b])=>compare.compareCodeUnits(a, b))){
|
|
150
|
+
if (plugin.enabled !== true || Object.hasOwn(strapi.plugins, name) === false || plugin.pathToPlugin === undefined || ts__namespace.sys.directoryExists(plugin.pathToPlugin) === false) {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const pluginPackageName = plugin.packageInfo?.name ?? plugin.info?.packageName;
|
|
154
|
+
if (pluginPackageName !== undefined && bundledPackages.has(pluginPackageName) === true) {
|
|
155
|
+
options.logger.debug(`Skipping ${name}: @strapi/strapi/strict-types loads its contracts.`);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const pluginDirectory = path__default.default.resolve(plugin.pathToPlugin);
|
|
159
|
+
const packageNames = new Set([
|
|
160
|
+
plugin.packageInfo?.name,
|
|
161
|
+
plugin.info?.packageName,
|
|
162
|
+
...Object.keys(dependencies)
|
|
163
|
+
]);
|
|
164
|
+
const candidates = [
|
|
165
|
+
...packageNames
|
|
166
|
+
].filter((packageName)=>typeof packageName === 'string').sort(compare.compareCodeUnits).map((packageName)=>`${packageName}/strapi-server`);
|
|
167
|
+
let declaration;
|
|
168
|
+
let specifier;
|
|
169
|
+
for (const candidate of candidates){
|
|
170
|
+
declaration = resolveDeclaration(candidate, containingFile, compilerOptions, pluginDirectory);
|
|
171
|
+
if (declaration !== undefined) {
|
|
172
|
+
specifier = candidate;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (declaration === undefined) {
|
|
177
|
+
// Legacy Node resolution ignores package exports. Resolve only the server export with
|
|
178
|
+
// modern resolution, then reference its declaration directly using the app's resolver.
|
|
179
|
+
for (const candidate of candidates){
|
|
180
|
+
declaration = resolveDeclaration(candidate, containingFile, modernOptions, pluginDirectory);
|
|
181
|
+
if (declaration !== undefined) {
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// Configured local plugins may have no node_modules entry. Package self-references
|
|
186
|
+
// still resolve their server exports from inside the plugin directory.
|
|
187
|
+
if (declaration === undefined && plugin.packageInfo?.name !== undefined) {
|
|
188
|
+
declaration = resolveDeclaration(`${plugin.packageInfo.name}/strapi-server`, path__default.default.join(pluginDirectory, 'package.json'), modernOptions, pluginDirectory);
|
|
189
|
+
}
|
|
190
|
+
declaration ?? (declaration = resolveDeclaration(path__default.default.join(pluginDirectory, 'strapi-server'), containingFile, compilerOptions, pluginDirectory));
|
|
191
|
+
if (declaration !== undefined) {
|
|
192
|
+
const relative = relativeImport(declaration, containingFile);
|
|
193
|
+
if (resolveDeclaration(relative, containingFile, compilerOptions, pluginDirectory) === declaration) {
|
|
194
|
+
specifier = relative;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (declaration !== undefined && specifier !== undefined) {
|
|
199
|
+
const strictOptIn = readStrictOptIn(declaration);
|
|
200
|
+
if (strictOptIn !== undefined) {
|
|
201
|
+
options.logger.warn(`The server declaration of ${name} ${strictOptIn}, which turns strict types on for every application that installs it. Report it to the plugin author.`);
|
|
202
|
+
}
|
|
203
|
+
const identity = realpath(declaration);
|
|
204
|
+
const previous = importsByDeclaration.get(identity);
|
|
205
|
+
if (previous === undefined || specifier < previous) {
|
|
206
|
+
importsByDeclaration.set(identity, specifier);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const imports = [
|
|
211
|
+
...importsByDeclaration.values()
|
|
212
|
+
].sort(compare.compareCodeUnits);
|
|
213
|
+
options.logger.debug(`Found ${imports.length} plugin server declarations.`);
|
|
214
|
+
const definitions = imports.map((specifier)=>ts__namespace.factory.createImportDeclaration(undefined, ts__namespace.factory.createImportClause(true, undefined, ts__namespace.factory.createNamedImports([])), ts__namespace.factory.createStringLiteral(specifier, true), undefined));
|
|
215
|
+
const output = imports.length === 0 ? 'export {};\n' : utils.emitDefinitions(definitions);
|
|
216
|
+
return {
|
|
217
|
+
output: await utils.format(output),
|
|
218
|
+
stats: {
|
|
219
|
+
plugins: imports.length
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
exports.generatePluginDefinitions = generatePluginDefinitions;
|
|
225
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/generators/plugins/index.ts"],"sourcesContent":["import path from 'node:path';\nimport * as ts from 'typescript';\n\nimport { emitDefinitions, format } from '../utils';\nimport type { GeneratorOptions } from '../utils';\nimport { compareCodeUnits } from '../common/compare';\n\ntype EnabledPlugin = {\n enabled: boolean;\n pathToPlugin?: string;\n packageInfo?: { name?: string };\n info?: { packageName?: string };\n};\n\nconst declarationExtensions = new Set<string>([\n ts.Extension.Dts,\n ts.Extension.Dmts,\n ts.Extension.Dcts,\n]);\n\nconst realpath = (filename: string) => ts.sys.realpath?.(filename) ?? path.resolve(filename);\n\nconst readCompilerOptions = (appDir: string): ts.CompilerOptions => {\n const configPath = path.join(appDir, 'tsconfig.json');\n if (ts.sys.fileExists(configPath) === false) {\n return { module: ts.ModuleKind.CommonJS, moduleResolution: ts.ModuleResolutionKind.Node10 };\n }\n\n const config = ts.readConfigFile(configPath, ts.sys.readFile);\n if (config.error !== undefined) {\n throw new Error(ts.flattenDiagnosticMessageText(config.error.messageText, '\\n'));\n }\n\n const parsed = ts.parseJsonConfigFileContent(\n config.config,\n ts.sys,\n appDir,\n undefined,\n configPath\n );\n // Generation may run before any input files exist. Invalid compiler options still matter.\n const errors = parsed.errors.filter((error) => error.code !== 18002 && error.code !== 18003);\n if (errors.length > 0) {\n throw new Error(\n errors.map((error) => ts.flattenDiagnosticMessageText(error.messageText, '\\n')).join('\\n')\n );\n }\n\n return parsed.options;\n};\n\nconst resolveDeclaration = (\n specifier: string,\n containingFile: string,\n compilerOptions: ts.CompilerOptions,\n pluginDirectory: string\n): string | undefined => {\n const mode = ts.getImpliedNodeFormatForFile(containingFile, undefined, ts.sys, compilerOptions);\n const resolved = ts.resolveModuleName(\n specifier,\n containingFile,\n compilerOptions,\n ts.sys,\n undefined,\n undefined,\n mode\n ).resolvedModule;\n\n if (resolved === undefined || declarationExtensions.has(resolved.extension) === false) {\n return undefined;\n }\n\n const filename = path.resolve(resolved.resolvedFileName);\n const relative = path.relative(realpath(pluginDirectory), realpath(filename));\n // An alias or a same-named package elsewhere must not import another plugin's contract.\n if (relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {\n return undefined;\n }\n\n return filename;\n};\n\nconst packageNameOf = (specifier: string) => {\n const segments = specifier.split('/');\n return (specifier.startsWith('@') ? segments.slice(0, 2) : segments.slice(0, 1)).join('/');\n};\n\n/**\n * Names of the packages `@strapi/strapi/strict-types` already loads. Their store path under a\n * strict package manager layout is machine-local, so they must not be imported again.\n */\nconst readBundledPackages = (\n containingFile: string,\n compilerOptionsList: ts.CompilerOptions[]\n): Set<string> => {\n for (const compilerOptions of compilerOptionsList) {\n const mode = ts.getImpliedNodeFormatForFile(containingFile, undefined, ts.sys, compilerOptions);\n const resolved = ts.resolveModuleName(\n '@strapi/strapi/strict-types',\n containingFile,\n compilerOptions,\n ts.sys,\n undefined,\n undefined,\n mode\n ).resolvedModule;\n if (resolved === undefined) {\n continue;\n }\n\n const contents = ts.sys.readFile(resolved.resolvedFileName);\n if (contents === undefined) {\n continue;\n }\n\n const { typeReferenceDirectives } = ts.preProcessFile(contents, false);\n return new Set(typeReferenceDirectives.map(({ fileName }) => packageNameOf(fileName)));\n }\n\n return new Set();\n};\n\nconst augmentsSettings = (node: ts.Node, namespaces: string[] = []): boolean => {\n const currentNamespaces = ts.isModuleDeclaration(node)\n ? [...namespaces, node.name.text]\n : namespaces;\n if (\n ts.isInterfaceDeclaration(node) &&\n node.name.text === 'Settings' &&\n currentNamespaces.slice(-2).join('.') === 'Strapi.Registries'\n ) {\n return true;\n }\n return ts.forEachChild(node, (child) => augmentsSettings(child, currentNamespaces)) === true;\n};\n\n/**\n * Why a plugin's server declaration opts its consumers in to strict types, if it does. Only the\n * entry file is read: a leaking import deeper in the plugin's declarations is not reported.\n */\nconst readStrictOptIn = (declaration: string): string | undefined => {\n const contents = ts.sys.readFile(declaration);\n if (contents === undefined) {\n return undefined;\n }\n\n const { importedFiles, typeReferenceDirectives } = ts.preProcessFile(contents, true);\n const references = [...importedFiles, ...typeReferenceDirectives];\n if (references.some(({ fileName }) => fileName === '@strapi/strapi/strict-types') === true) {\n return 'imports @strapi/strapi/strict-types';\n }\n\n const source = ts.createSourceFile(declaration, contents, ts.ScriptTarget.Latest);\n return augmentsSettings(source) === true ? 'augments Strapi.Registries.Settings' : undefined;\n};\n\nconst relativeImport = (filename: string, containingFile: string) => {\n const relative = path.relative(path.dirname(containingFile), filename).split(path.sep).join('/');\n return relative.startsWith('../') ? relative : `./${relative}`;\n};\n\n/** Imports the server declarations of enabled, loaded plugins without enabling strict typing. */\nexport const generatePluginDefinitions = async (options: GeneratorOptions) => {\n const { strapi } = options;\n const appDir = options.appDir ?? process.cwd();\n const containingFile = path.join(options.pwd ?? appDir, 'plugins.d.ts');\n // Preserve the installed path in generated imports, including workspace and pnpm links.\n // Canonical paths are used only to identify the plugin and deduplicate declarations.\n const compilerOptions = { ...readCompilerOptions(appDir), preserveSymlinks: true };\n const modernOptions = {\n ...compilerOptions,\n module: ts.ModuleKind.NodeNext,\n moduleResolution: ts.ModuleResolutionKind.NodeNext,\n };\n const enabledPlugins: Record<string, EnabledPlugin> = strapi.config.get('enabledPlugins', {});\n const dependencies: Record<string, unknown> = strapi.config.get('info.dependencies', {});\n const importsByDeclaration = new Map<string, string>();\n const bundledPackages = readBundledPackages(containingFile, [compilerOptions, modernOptions]);\n\n for (const [name, plugin] of Object.entries(enabledPlugins).sort(([a], [b]) =>\n compareCodeUnits(a, b)\n )) {\n if (\n plugin.enabled !== true ||\n Object.hasOwn(strapi.plugins, name) === false ||\n plugin.pathToPlugin === undefined ||\n ts.sys.directoryExists(plugin.pathToPlugin) === false\n ) {\n continue;\n }\n\n const pluginPackageName = plugin.packageInfo?.name ?? plugin.info?.packageName;\n if (pluginPackageName !== undefined && bundledPackages.has(pluginPackageName) === true) {\n options.logger.debug(`Skipping ${name}: @strapi/strapi/strict-types loads its contracts.`);\n continue;\n }\n\n const pluginDirectory = path.resolve(plugin.pathToPlugin);\n const packageNames = new Set([\n plugin.packageInfo?.name,\n plugin.info?.packageName,\n ...Object.keys(dependencies),\n ]);\n const candidates = [...packageNames]\n .filter((packageName): packageName is string => typeof packageName === 'string')\n .sort(compareCodeUnits)\n .map((packageName) => `${packageName}/strapi-server`);\n\n let declaration: string | undefined;\n let specifier: string | undefined;\n for (const candidate of candidates) {\n declaration = resolveDeclaration(candidate, containingFile, compilerOptions, pluginDirectory);\n if (declaration !== undefined) {\n specifier = candidate;\n break;\n }\n }\n\n if (declaration === undefined) {\n // Legacy Node resolution ignores package exports. Resolve only the server export with\n // modern resolution, then reference its declaration directly using the app's resolver.\n for (const candidate of candidates) {\n declaration = resolveDeclaration(candidate, containingFile, modernOptions, pluginDirectory);\n if (declaration !== undefined) {\n break;\n }\n }\n\n // Configured local plugins may have no node_modules entry. Package self-references\n // still resolve their server exports from inside the plugin directory.\n if (declaration === undefined && plugin.packageInfo?.name !== undefined) {\n declaration = resolveDeclaration(\n `${plugin.packageInfo.name}/strapi-server`,\n path.join(pluginDirectory, 'package.json'),\n modernOptions,\n pluginDirectory\n );\n }\n\n declaration ??= resolveDeclaration(\n path.join(pluginDirectory, 'strapi-server'),\n containingFile,\n compilerOptions,\n pluginDirectory\n );\n\n if (declaration !== undefined) {\n const relative = relativeImport(declaration, containingFile);\n if (\n resolveDeclaration(relative, containingFile, compilerOptions, pluginDirectory) ===\n declaration\n ) {\n specifier = relative;\n }\n }\n }\n\n if (declaration !== undefined && specifier !== undefined) {\n const strictOptIn = readStrictOptIn(declaration);\n if (strictOptIn !== undefined) {\n options.logger.warn(\n `The server declaration of ${name} ${strictOptIn}, which turns strict types on for every application that installs it. Report it to the plugin author.`\n );\n }\n\n const identity = realpath(declaration);\n const previous = importsByDeclaration.get(identity);\n if (previous === undefined || specifier < previous) {\n importsByDeclaration.set(identity, specifier);\n }\n }\n }\n\n const imports = [...importsByDeclaration.values()].sort(compareCodeUnits);\n options.logger.debug(`Found ${imports.length} plugin server declarations.`);\n\n const definitions = imports.map((specifier) =>\n ts.factory.createImportDeclaration(\n undefined,\n ts.factory.createImportClause(true, undefined, ts.factory.createNamedImports([])),\n ts.factory.createStringLiteral(specifier, true),\n undefined\n )\n );\n const output = imports.length === 0 ? 'export {};\\n' : emitDefinitions(definitions);\n\n return { output: await format(output), stats: { plugins: imports.length } };\n};\n"],"names":["declarationExtensions","Set","ts","Extension","Dts","Dmts","Dcts","realpath","filename","sys","path","resolve","readCompilerOptions","appDir","configPath","join","fileExists","module","ModuleKind","CommonJS","moduleResolution","ModuleResolutionKind","Node10","config","readConfigFile","readFile","error","undefined","Error","flattenDiagnosticMessageText","messageText","parsed","parseJsonConfigFileContent","errors","filter","code","length","map","options","resolveDeclaration","specifier","containingFile","compilerOptions","pluginDirectory","mode","getImpliedNodeFormatForFile","resolved","resolveModuleName","resolvedModule","has","extension","resolvedFileName","relative","startsWith","sep","isAbsolute","packageNameOf","segments","split","slice","readBundledPackages","compilerOptionsList","contents","typeReferenceDirectives","preProcessFile","fileName","augmentsSettings","node","namespaces","currentNamespaces","isModuleDeclaration","name","text","isInterfaceDeclaration","forEachChild","child","readStrictOptIn","declaration","importedFiles","references","some","source","createSourceFile","ScriptTarget","Latest","relativeImport","dirname","generatePluginDefinitions","strapi","process","cwd","pwd","preserveSymlinks","modernOptions","NodeNext","enabledPlugins","get","dependencies","importsByDeclaration","Map","bundledPackages","plugin","Object","entries","sort","a","b","compareCodeUnits","enabled","hasOwn","plugins","pathToPlugin","directoryExists","pluginPackageName","packageInfo","info","packageName","logger","debug","packageNames","keys","candidates","candidate","strictOptIn","warn","identity","previous","set","imports","values","definitions","factory","createImportDeclaration","createImportClause","createNamedImports","createStringLiteral","output","emitDefinitions","format","stats"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,MAAMA,qBAAAA,GAAwB,IAAIC,GA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AAUrF,SAAAA,CAAAA;AACrC,YAAA;AACF,QAAA;AACF,IAAA;AAEA,IAAA,MAAMwF,OAAAA,GAAU;AAAI9B,QAAAA,GAAAA,oBAAAA,CAAqB+B,MAAM;AAAG,KAAA,CAACzB,IAAI,CAACG,wBAAAA,CAAAA;IACxDrE,OAAAA,CAAQ+E,MAAM,CAACC,KAAK,CAAC,CAAC,MAAM,EAAEU,OAAAA,CAAQ5F,MAAM,CAAC,4BAA4B,CAAC,CAAA;AAE1E,IAAA,MAAM8F,WAAAA,GAAcF,OAAAA,CAAQ3F,GAAG,CAAC,CAACG,SAAAA,GAC/BtC,aAAAA,CAAGiI,OAAO,CAACC,uBAAuB,CAChCzG,SAAAA,EACAzB,aAAAA,CAAGiI,OAAO,CAACE,kBAAkB,CAAC,IAAA,EAAM1G,SAAAA,EAAWzB,aAAAA,CAAGiI,OAAO,CAACG,kBAAkB,CAAC,EAAE,CAAA,CAAA,EAC/EpI,aAAAA,CAAGiI,OAAO,CAACI,mBAAmB,CAAC/F,WAAW,IAAA,CAAA,EAC1Cb,SAAAA,CAAAA,CAAAA;AAGJ,IAAA,MAAM6G,SAASR,OAAAA,CAAQ5F,MAAM,KAAK,CAAA,GAAI,iBAAiBqG,qBAAAA,CAAgBP,WAAAA,CAAAA;IAEvE,OAAO;AAAEM,QAAAA,MAAAA,EAAQ,MAAME,YAAAA,CAAOF,MAAAA,CAAAA;QAASG,KAAAA,EAAO;AAAE7B,YAAAA,OAAAA,EAASkB,QAAQ5F;AAAO;AAAE,KAAA;AAC5E;;;;"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import * as ts from 'typescript';
|
|
3
|
+
import { emitDefinitions, format } from '../utils.mjs';
|
|
4
|
+
import { compareCodeUnits } from '../common/compare.mjs';
|
|
5
|
+
|
|
6
|
+
const declarationExtensions = new Set([
|
|
7
|
+
ts.Extension.Dts,
|
|
8
|
+
ts.Extension.Dmts,
|
|
9
|
+
ts.Extension.Dcts
|
|
10
|
+
]);
|
|
11
|
+
const realpath = (filename)=>ts.sys.realpath?.(filename) ?? path.resolve(filename);
|
|
12
|
+
const readCompilerOptions = (appDir)=>{
|
|
13
|
+
const configPath = path.join(appDir, 'tsconfig.json');
|
|
14
|
+
if (ts.sys.fileExists(configPath) === false) {
|
|
15
|
+
return {
|
|
16
|
+
module: ts.ModuleKind.CommonJS,
|
|
17
|
+
moduleResolution: ts.ModuleResolutionKind.Node10
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const config = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
21
|
+
if (config.error !== undefined) {
|
|
22
|
+
throw new Error(ts.flattenDiagnosticMessageText(config.error.messageText, '\n'));
|
|
23
|
+
}
|
|
24
|
+
const parsed = ts.parseJsonConfigFileContent(config.config, ts.sys, appDir, undefined, configPath);
|
|
25
|
+
// Generation may run before any input files exist. Invalid compiler options still matter.
|
|
26
|
+
const errors = parsed.errors.filter((error)=>error.code !== 18002 && error.code !== 18003);
|
|
27
|
+
if (errors.length > 0) {
|
|
28
|
+
throw new Error(errors.map((error)=>ts.flattenDiagnosticMessageText(error.messageText, '\n')).join('\n'));
|
|
29
|
+
}
|
|
30
|
+
return parsed.options;
|
|
31
|
+
};
|
|
32
|
+
const resolveDeclaration = (specifier, containingFile, compilerOptions, pluginDirectory)=>{
|
|
33
|
+
const mode = ts.getImpliedNodeFormatForFile(containingFile, undefined, ts.sys, compilerOptions);
|
|
34
|
+
const resolved = ts.resolveModuleName(specifier, containingFile, compilerOptions, ts.sys, undefined, undefined, mode).resolvedModule;
|
|
35
|
+
if (resolved === undefined || declarationExtensions.has(resolved.extension) === false) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const filename = path.resolve(resolved.resolvedFileName);
|
|
39
|
+
const relative = path.relative(realpath(pluginDirectory), realpath(filename));
|
|
40
|
+
// An alias or a same-named package elsewhere must not import another plugin's contract.
|
|
41
|
+
if (relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
return filename;
|
|
45
|
+
};
|
|
46
|
+
const packageNameOf = (specifier)=>{
|
|
47
|
+
const segments = specifier.split('/');
|
|
48
|
+
return (specifier.startsWith('@') ? segments.slice(0, 2) : segments.slice(0, 1)).join('/');
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Names of the packages `@strapi/strapi/strict-types` already loads. Their store path under a
|
|
52
|
+
* strict package manager layout is machine-local, so they must not be imported again.
|
|
53
|
+
*/ const readBundledPackages = (containingFile, compilerOptionsList)=>{
|
|
54
|
+
for (const compilerOptions of compilerOptionsList){
|
|
55
|
+
const mode = ts.getImpliedNodeFormatForFile(containingFile, undefined, ts.sys, compilerOptions);
|
|
56
|
+
const resolved = ts.resolveModuleName('@strapi/strapi/strict-types', containingFile, compilerOptions, ts.sys, undefined, undefined, mode).resolvedModule;
|
|
57
|
+
if (resolved === undefined) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const contents = ts.sys.readFile(resolved.resolvedFileName);
|
|
61
|
+
if (contents === undefined) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const { typeReferenceDirectives } = ts.preProcessFile(contents, false);
|
|
65
|
+
return new Set(typeReferenceDirectives.map(({ fileName })=>packageNameOf(fileName)));
|
|
66
|
+
}
|
|
67
|
+
return new Set();
|
|
68
|
+
};
|
|
69
|
+
const augmentsSettings = (node, namespaces = [])=>{
|
|
70
|
+
const currentNamespaces = ts.isModuleDeclaration(node) ? [
|
|
71
|
+
...namespaces,
|
|
72
|
+
node.name.text
|
|
73
|
+
] : namespaces;
|
|
74
|
+
if (ts.isInterfaceDeclaration(node) && node.name.text === 'Settings' && currentNamespaces.slice(-2).join('.') === 'Strapi.Registries') {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
return ts.forEachChild(node, (child)=>augmentsSettings(child, currentNamespaces)) === true;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Why a plugin's server declaration opts its consumers in to strict types, if it does. Only the
|
|
81
|
+
* entry file is read: a leaking import deeper in the plugin's declarations is not reported.
|
|
82
|
+
*/ const readStrictOptIn = (declaration)=>{
|
|
83
|
+
const contents = ts.sys.readFile(declaration);
|
|
84
|
+
if (contents === undefined) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
const { importedFiles, typeReferenceDirectives } = ts.preProcessFile(contents, true);
|
|
88
|
+
const references = [
|
|
89
|
+
...importedFiles,
|
|
90
|
+
...typeReferenceDirectives
|
|
91
|
+
];
|
|
92
|
+
if (references.some(({ fileName })=>fileName === '@strapi/strapi/strict-types') === true) {
|
|
93
|
+
return 'imports @strapi/strapi/strict-types';
|
|
94
|
+
}
|
|
95
|
+
const source = ts.createSourceFile(declaration, contents, ts.ScriptTarget.Latest);
|
|
96
|
+
return augmentsSettings(source) === true ? 'augments Strapi.Registries.Settings' : undefined;
|
|
97
|
+
};
|
|
98
|
+
const relativeImport = (filename, containingFile)=>{
|
|
99
|
+
const relative = path.relative(path.dirname(containingFile), filename).split(path.sep).join('/');
|
|
100
|
+
return relative.startsWith('../') ? relative : `./${relative}`;
|
|
101
|
+
};
|
|
102
|
+
/** Imports the server declarations of enabled, loaded plugins without enabling strict typing. */ const generatePluginDefinitions = async (options)=>{
|
|
103
|
+
const { strapi } = options;
|
|
104
|
+
const appDir = options.appDir ?? process.cwd();
|
|
105
|
+
const containingFile = path.join(options.pwd ?? appDir, 'plugins.d.ts');
|
|
106
|
+
// Preserve the installed path in generated imports, including workspace and pnpm links.
|
|
107
|
+
// Canonical paths are used only to identify the plugin and deduplicate declarations.
|
|
108
|
+
const compilerOptions = {
|
|
109
|
+
...readCompilerOptions(appDir),
|
|
110
|
+
preserveSymlinks: true
|
|
111
|
+
};
|
|
112
|
+
const modernOptions = {
|
|
113
|
+
...compilerOptions,
|
|
114
|
+
module: ts.ModuleKind.NodeNext,
|
|
115
|
+
moduleResolution: ts.ModuleResolutionKind.NodeNext
|
|
116
|
+
};
|
|
117
|
+
const enabledPlugins = strapi.config.get('enabledPlugins', {});
|
|
118
|
+
const dependencies = strapi.config.get('info.dependencies', {});
|
|
119
|
+
const importsByDeclaration = new Map();
|
|
120
|
+
const bundledPackages = readBundledPackages(containingFile, [
|
|
121
|
+
compilerOptions,
|
|
122
|
+
modernOptions
|
|
123
|
+
]);
|
|
124
|
+
for (const [name, plugin] of Object.entries(enabledPlugins).sort(([a], [b])=>compareCodeUnits(a, b))){
|
|
125
|
+
if (plugin.enabled !== true || Object.hasOwn(strapi.plugins, name) === false || plugin.pathToPlugin === undefined || ts.sys.directoryExists(plugin.pathToPlugin) === false) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const pluginPackageName = plugin.packageInfo?.name ?? plugin.info?.packageName;
|
|
129
|
+
if (pluginPackageName !== undefined && bundledPackages.has(pluginPackageName) === true) {
|
|
130
|
+
options.logger.debug(`Skipping ${name}: @strapi/strapi/strict-types loads its contracts.`);
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const pluginDirectory = path.resolve(plugin.pathToPlugin);
|
|
134
|
+
const packageNames = new Set([
|
|
135
|
+
plugin.packageInfo?.name,
|
|
136
|
+
plugin.info?.packageName,
|
|
137
|
+
...Object.keys(dependencies)
|
|
138
|
+
]);
|
|
139
|
+
const candidates = [
|
|
140
|
+
...packageNames
|
|
141
|
+
].filter((packageName)=>typeof packageName === 'string').sort(compareCodeUnits).map((packageName)=>`${packageName}/strapi-server`);
|
|
142
|
+
let declaration;
|
|
143
|
+
let specifier;
|
|
144
|
+
for (const candidate of candidates){
|
|
145
|
+
declaration = resolveDeclaration(candidate, containingFile, compilerOptions, pluginDirectory);
|
|
146
|
+
if (declaration !== undefined) {
|
|
147
|
+
specifier = candidate;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (declaration === undefined) {
|
|
152
|
+
// Legacy Node resolution ignores package exports. Resolve only the server export with
|
|
153
|
+
// modern resolution, then reference its declaration directly using the app's resolver.
|
|
154
|
+
for (const candidate of candidates){
|
|
155
|
+
declaration = resolveDeclaration(candidate, containingFile, modernOptions, pluginDirectory);
|
|
156
|
+
if (declaration !== undefined) {
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// Configured local plugins may have no node_modules entry. Package self-references
|
|
161
|
+
// still resolve their server exports from inside the plugin directory.
|
|
162
|
+
if (declaration === undefined && plugin.packageInfo?.name !== undefined) {
|
|
163
|
+
declaration = resolveDeclaration(`${plugin.packageInfo.name}/strapi-server`, path.join(pluginDirectory, 'package.json'), modernOptions, pluginDirectory);
|
|
164
|
+
}
|
|
165
|
+
declaration ?? (declaration = resolveDeclaration(path.join(pluginDirectory, 'strapi-server'), containingFile, compilerOptions, pluginDirectory));
|
|
166
|
+
if (declaration !== undefined) {
|
|
167
|
+
const relative = relativeImport(declaration, containingFile);
|
|
168
|
+
if (resolveDeclaration(relative, containingFile, compilerOptions, pluginDirectory) === declaration) {
|
|
169
|
+
specifier = relative;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (declaration !== undefined && specifier !== undefined) {
|
|
174
|
+
const strictOptIn = readStrictOptIn(declaration);
|
|
175
|
+
if (strictOptIn !== undefined) {
|
|
176
|
+
options.logger.warn(`The server declaration of ${name} ${strictOptIn}, which turns strict types on for every application that installs it. Report it to the plugin author.`);
|
|
177
|
+
}
|
|
178
|
+
const identity = realpath(declaration);
|
|
179
|
+
const previous = importsByDeclaration.get(identity);
|
|
180
|
+
if (previous === undefined || specifier < previous) {
|
|
181
|
+
importsByDeclaration.set(identity, specifier);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const imports = [
|
|
186
|
+
...importsByDeclaration.values()
|
|
187
|
+
].sort(compareCodeUnits);
|
|
188
|
+
options.logger.debug(`Found ${imports.length} plugin server declarations.`);
|
|
189
|
+
const definitions = imports.map((specifier)=>ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(true, undefined, ts.factory.createNamedImports([])), ts.factory.createStringLiteral(specifier, true), undefined));
|
|
190
|
+
const output = imports.length === 0 ? 'export {};\n' : emitDefinitions(definitions);
|
|
191
|
+
return {
|
|
192
|
+
output: await format(output),
|
|
193
|
+
stats: {
|
|
194
|
+
plugins: imports.length
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export { generatePluginDefinitions };
|
|
200
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/generators/plugins/index.ts"],"sourcesContent":["import path from 'node:path';\nimport * as ts from 'typescript';\n\nimport { emitDefinitions, format } from '../utils';\nimport type { GeneratorOptions } from '../utils';\nimport { compareCodeUnits } from '../common/compare';\n\ntype EnabledPlugin = {\n enabled: boolean;\n pathToPlugin?: string;\n packageInfo?: { name?: string };\n info?: { packageName?: string };\n};\n\nconst declarationExtensions = new Set<string>([\n ts.Extension.Dts,\n ts.Extension.Dmts,\n ts.Extension.Dcts,\n]);\n\nconst realpath = (filename: string) => ts.sys.realpath?.(filename) ?? path.resolve(filename);\n\nconst readCompilerOptions = (appDir: string): ts.CompilerOptions => {\n const configPath = path.join(appDir, 'tsconfig.json');\n if (ts.sys.fileExists(configPath) === false) {\n return { module: ts.ModuleKind.CommonJS, moduleResolution: ts.ModuleResolutionKind.Node10 };\n }\n\n const config = ts.readConfigFile(configPath, ts.sys.readFile);\n if (config.error !== undefined) {\n throw new Error(ts.flattenDiagnosticMessageText(config.error.messageText, '\\n'));\n }\n\n const parsed = ts.parseJsonConfigFileContent(\n config.config,\n ts.sys,\n appDir,\n undefined,\n configPath\n );\n // Generation may run before any input files exist. Invalid compiler options still matter.\n const errors = parsed.errors.filter((error) => error.code !== 18002 && error.code !== 18003);\n if (errors.length > 0) {\n throw new Error(\n errors.map((error) => ts.flattenDiagnosticMessageText(error.messageText, '\\n')).join('\\n')\n );\n }\n\n return parsed.options;\n};\n\nconst resolveDeclaration = (\n specifier: string,\n containingFile: string,\n compilerOptions: ts.CompilerOptions,\n pluginDirectory: string\n): string | undefined => {\n const mode = ts.getImpliedNodeFormatForFile(containingFile, undefined, ts.sys, compilerOptions);\n const resolved = ts.resolveModuleName(\n specifier,\n containingFile,\n compilerOptions,\n ts.sys,\n undefined,\n undefined,\n mode\n ).resolvedModule;\n\n if (resolved === undefined || declarationExtensions.has(resolved.extension) === false) {\n return undefined;\n }\n\n const filename = path.resolve(resolved.resolvedFileName);\n const relative = path.relative(realpath(pluginDirectory), realpath(filename));\n // An alias or a same-named package elsewhere must not import another plugin's contract.\n if (relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {\n return undefined;\n }\n\n return filename;\n};\n\nconst packageNameOf = (specifier: string) => {\n const segments = specifier.split('/');\n return (specifier.startsWith('@') ? segments.slice(0, 2) : segments.slice(0, 1)).join('/');\n};\n\n/**\n * Names of the packages `@strapi/strapi/strict-types` already loads. Their store path under a\n * strict package manager layout is machine-local, so they must not be imported again.\n */\nconst readBundledPackages = (\n containingFile: string,\n compilerOptionsList: ts.CompilerOptions[]\n): Set<string> => {\n for (const compilerOptions of compilerOptionsList) {\n const mode = ts.getImpliedNodeFormatForFile(containingFile, undefined, ts.sys, compilerOptions);\n const resolved = ts.resolveModuleName(\n '@strapi/strapi/strict-types',\n containingFile,\n compilerOptions,\n ts.sys,\n undefined,\n undefined,\n mode\n ).resolvedModule;\n if (resolved === undefined) {\n continue;\n }\n\n const contents = ts.sys.readFile(resolved.resolvedFileName);\n if (contents === undefined) {\n continue;\n }\n\n const { typeReferenceDirectives } = ts.preProcessFile(contents, false);\n return new Set(typeReferenceDirectives.map(({ fileName }) => packageNameOf(fileName)));\n }\n\n return new Set();\n};\n\nconst augmentsSettings = (node: ts.Node, namespaces: string[] = []): boolean => {\n const currentNamespaces = ts.isModuleDeclaration(node)\n ? [...namespaces, node.name.text]\n : namespaces;\n if (\n ts.isInterfaceDeclaration(node) &&\n node.name.text === 'Settings' &&\n currentNamespaces.slice(-2).join('.') === 'Strapi.Registries'\n ) {\n return true;\n }\n return ts.forEachChild(node, (child) => augmentsSettings(child, currentNamespaces)) === true;\n};\n\n/**\n * Why a plugin's server declaration opts its consumers in to strict types, if it does. Only the\n * entry file is read: a leaking import deeper in the plugin's declarations is not reported.\n */\nconst readStrictOptIn = (declaration: string): string | undefined => {\n const contents = ts.sys.readFile(declaration);\n if (contents === undefined) {\n return undefined;\n }\n\n const { importedFiles, typeReferenceDirectives } = ts.preProcessFile(contents, true);\n const references = [...importedFiles, ...typeReferenceDirectives];\n if (references.some(({ fileName }) => fileName === '@strapi/strapi/strict-types') === true) {\n return 'imports @strapi/strapi/strict-types';\n }\n\n const source = ts.createSourceFile(declaration, contents, ts.ScriptTarget.Latest);\n return augmentsSettings(source) === true ? 'augments Strapi.Registries.Settings' : undefined;\n};\n\nconst relativeImport = (filename: string, containingFile: string) => {\n const relative = path.relative(path.dirname(containingFile), filename).split(path.sep).join('/');\n return relative.startsWith('../') ? relative : `./${relative}`;\n};\n\n/** Imports the server declarations of enabled, loaded plugins without enabling strict typing. */\nexport const generatePluginDefinitions = async (options: GeneratorOptions) => {\n const { strapi } = options;\n const appDir = options.appDir ?? process.cwd();\n const containingFile = path.join(options.pwd ?? appDir, 'plugins.d.ts');\n // Preserve the installed path in generated imports, including workspace and pnpm links.\n // Canonical paths are used only to identify the plugin and deduplicate declarations.\n const compilerOptions = { ...readCompilerOptions(appDir), preserveSymlinks: true };\n const modernOptions = {\n ...compilerOptions,\n module: ts.ModuleKind.NodeNext,\n moduleResolution: ts.ModuleResolutionKind.NodeNext,\n };\n const enabledPlugins: Record<string, EnabledPlugin> = strapi.config.get('enabledPlugins', {});\n const dependencies: Record<string, unknown> = strapi.config.get('info.dependencies', {});\n const importsByDeclaration = new Map<string, string>();\n const bundledPackages = readBundledPackages(containingFile, [compilerOptions, modernOptions]);\n\n for (const [name, plugin] of Object.entries(enabledPlugins).sort(([a], [b]) =>\n compareCodeUnits(a, b)\n )) {\n if (\n plugin.enabled !== true ||\n Object.hasOwn(strapi.plugins, name) === false ||\n plugin.pathToPlugin === undefined ||\n ts.sys.directoryExists(plugin.pathToPlugin) === false\n ) {\n continue;\n }\n\n const pluginPackageName = plugin.packageInfo?.name ?? plugin.info?.packageName;\n if (pluginPackageName !== undefined && bundledPackages.has(pluginPackageName) === true) {\n options.logger.debug(`Skipping ${name}: @strapi/strapi/strict-types loads its contracts.`);\n continue;\n }\n\n const pluginDirectory = path.resolve(plugin.pathToPlugin);\n const packageNames = new Set([\n plugin.packageInfo?.name,\n plugin.info?.packageName,\n ...Object.keys(dependencies),\n ]);\n const candidates = [...packageNames]\n .filter((packageName): packageName is string => typeof packageName === 'string')\n .sort(compareCodeUnits)\n .map((packageName) => `${packageName}/strapi-server`);\n\n let declaration: string | undefined;\n let specifier: string | undefined;\n for (const candidate of candidates) {\n declaration = resolveDeclaration(candidate, containingFile, compilerOptions, pluginDirectory);\n if (declaration !== undefined) {\n specifier = candidate;\n break;\n }\n }\n\n if (declaration === undefined) {\n // Legacy Node resolution ignores package exports. Resolve only the server export with\n // modern resolution, then reference its declaration directly using the app's resolver.\n for (const candidate of candidates) {\n declaration = resolveDeclaration(candidate, containingFile, modernOptions, pluginDirectory);\n if (declaration !== undefined) {\n break;\n }\n }\n\n // Configured local plugins may have no node_modules entry. Package self-references\n // still resolve their server exports from inside the plugin directory.\n if (declaration === undefined && plugin.packageInfo?.name !== undefined) {\n declaration = resolveDeclaration(\n `${plugin.packageInfo.name}/strapi-server`,\n path.join(pluginDirectory, 'package.json'),\n modernOptions,\n pluginDirectory\n );\n }\n\n declaration ??= resolveDeclaration(\n path.join(pluginDirectory, 'strapi-server'),\n containingFile,\n compilerOptions,\n pluginDirectory\n );\n\n if (declaration !== undefined) {\n const relative = relativeImport(declaration, containingFile);\n if (\n resolveDeclaration(relative, containingFile, compilerOptions, pluginDirectory) ===\n declaration\n ) {\n specifier = relative;\n }\n }\n }\n\n if (declaration !== undefined && specifier !== undefined) {\n const strictOptIn = readStrictOptIn(declaration);\n if (strictOptIn !== undefined) {\n options.logger.warn(\n `The server declaration of ${name} ${strictOptIn}, which turns strict types on for every application that installs it. Report it to the plugin author.`\n );\n }\n\n const identity = realpath(declaration);\n const previous = importsByDeclaration.get(identity);\n if (previous === undefined || specifier < previous) {\n importsByDeclaration.set(identity, specifier);\n }\n }\n }\n\n const imports = [...importsByDeclaration.values()].sort(compareCodeUnits);\n options.logger.debug(`Found ${imports.length} plugin server declarations.`);\n\n const definitions = imports.map((specifier) =>\n ts.factory.createImportDeclaration(\n undefined,\n ts.factory.createImportClause(true, undefined, ts.factory.createNamedImports([])),\n ts.factory.createStringLiteral(specifier, true),\n undefined\n )\n );\n const output = imports.length === 0 ? 'export {};\\n' : emitDefinitions(definitions);\n\n return { output: await format(output), stats: { plugins: imports.length } };\n};\n"],"names":["declarationExtensions","Set","ts","Extension","Dts","Dmts","Dcts","realpath","filename","sys","path","resolve","readCompilerOptions","appDir","configPath","join","fileExists","module","ModuleKind","CommonJS","moduleResolution","ModuleResolutionKind","Node10","config","readConfigFile","readFile","error","undefined","Error","flattenDiagnosticMessageText","messageText","parsed","parseJsonConfigFileContent","errors","filter","code","length","map","options","resolveDeclaration","specifier","containingFile","compilerOptions","pluginDirectory","mode","getImpliedNodeFormatForFile","resolved","resolveModuleName","resolvedModule","has","extension","resolvedFileName","relative","startsWith","sep","isAbsolute","packageNameOf","segments","split","slice","readBundledPackages","compilerOptionsList","contents","typeReferenceDirectives","preProcessFile","fileName","augmentsSettings","node","namespaces","currentNamespaces","isModuleDeclaration","name","text","isInterfaceDeclaration","forEachChild","child","readStrictOptIn","declaration","importedFiles","references","some","source","createSourceFile","ScriptTarget","Latest","relativeImport","dirname","generatePluginDefinitions","strapi","process","cwd","pwd","preserveSymlinks","modernOptions","NodeNext","enabledPlugins","get","dependencies","importsByDeclaration","Map","bundledPackages","plugin","Object","entries","sort","a","b","compareCodeUnits","enabled","hasOwn","plugins","pathToPlugin","directoryExists","pluginPackageName","packageInfo","info","packageName","logger","debug","packageNames","keys","candidates","candidate","strictOptIn","warn","identity","previous","set","imports","values","definitions","factory","createImportDeclaration","createImportClause","createNamedImports","createStringLiteral","output","emitDefinitions","format","stats"],"mappings":";;;;;AAcA,MAAMA,qBAAAA,GAAwB,IAAIC,GAAAA,CAAY;IAC5CC,EAAAA,CAAGC,SAAS,CAACC,GAAG;IAChBF,EAAAA,CAAGC,SAAS,CAACE,IAAI;IACjBH,EAAAA,CAAGC,SAAS,CAACG;AACd,CAAA,CAAA;AAED,MAAMC,QAAAA,GAAW,CAACC,QAAAA,GAAqBN,EAAAA,CAAGO,GAAG,CAACF,QAAQ,GAAGC,QAAAA,CAAAA,IAAaE,IAAAA,CAAKC,OAAO,CAACH,QAAAA,CAAAA;AAEnF,MAAMI,sBAAsB,CAACC,MAAAA,GAAAA;AAC3B,IAAA,MAAMC,UAAAA,GAAaJ,IAAAA,CAAKK,IAAI,CAACF,MAAAA,EAAQ,eAAA,CAAA;AACrC,IAAA,IAAIX,GAAGO,GAAG,CAACO,UAAU,CAACF,gBAAgB,KAAA,EAAO;QAC3C,OAAO;YAAEG,MAAAA,EAAQf,EAAAA,CAAGgB,UAAU,CAACC,QAAQ;YAAEC,gBAAAA,EAAkBlB,EAAAA,CAAGmB,oBAAoB,CAACC;AAAO,SAAA;AAC5F,IAAA;IAEA,MAAMC,MAAAA,GAASrB,GAAGsB,cAAc,CAACV,YAAYZ,EAAAA,CAAGO,GAAG,CAACgB,QAAQ,CAAA;IAC5D,IAAIF,MAAAA,CAAOG,KAAK,KAAKC,SAAAA,EAAW;QAC9B,MAAM,IAAIC,MAAM1B,EAAAA,CAAG2B,4BAA4B,CAACN,MAAAA,CAAOG,KAAK,CAACI,WAAW,EAAE,IAAA,CAAA,CAAA;AAC5E,IAAA;IAEA,MAAMC,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;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { GeneratorOptions } from '../utils';
|
|
2
|
+
/**
|
|
3
|
+
* Generate type definitions for the application's policies (global::* and api::*)
|
|
4
|
+
*
|
|
5
|
+
* Policies are typed from their source file, so only the ones with a source in src/policies or
|
|
6
|
+
* src/api are emitted. Plugin and admin policies are left to the packages themselves
|
|
7
|
+
* (Strapi.Registries.PackagePolicies), so registering application policies keeps them accepted.
|
|
8
|
+
*
|
|
9
|
+
* declare global {
|
|
10
|
+
* namespace Strapi {
|
|
11
|
+
* namespace Registries {
|
|
12
|
+
* interface AppPolicies {
|
|
13
|
+
* 'global::<policy>': PolicyConfig<typeof import('<relative path to the source>')>;
|
|
14
|
+
* 'api::<api>.<policy>': PolicyConfig<typeof import('<relative path to the source>')>;
|
|
15
|
+
* 'global::<js policy>': unknown;
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* The import of a JS policy is an error type without `allowJs`, and one such entry turns every policy
|
|
22
|
+
* reference into `any`. JS policies are registered as `unknown` without an import.
|
|
23
|
+
* TODO @Nico with `allowJs`, a JSDoc-typed JS policy could register its config like a TS one
|
|
24
|
+
*/
|
|
25
|
+
export declare const generatePoliciesDefinitions: (options?: GeneratorOptions) => Promise<{
|
|
26
|
+
output: string;
|
|
27
|
+
stats: {};
|
|
28
|
+
}>;
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/generators/policies/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAmIjD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,2BAA2B,GACtC,UAAS,gBAAyC;;;EAkCnD,CAAC"}
|