@flarum/cli 3.0.11 → 3.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -1
- package/bin/libgit2.1.5.dylib +0 -0
- package/bin/splitsh-lite-darwin-arm64 +0 -0
- package/boilerplate/skeleton/extension/composer.json +4 -0
- package/boilerplate/skeleton/extension/js/package.json +5 -5
- package/boilerplate/skeleton/extension/js/tsconfig.json +3 -0
- package/boilerplate/skeleton/extension/js/tsconfig.test.json +1 -0
- package/boilerplate/skeleton/extension/phpstan.neon +0 -1
- package/boilerplate/skeleton/extension/tests/phpunit.integration.xml +1 -0
- package/boilerplate/skeleton/extension/tests/phpunit.unit.xml +2 -1
- package/boilerplate/stubs/backend/advanced-api-resource.php +3 -3
- package/boilerplate/stubs/backend/model-factory.php +17 -0
- package/boilerplate/stubs/backend/model.php +3 -0
- package/lib/base-command.d.ts +21 -3
- package/lib/base-command.js +52 -5
- package/lib/commands/make/backend/model.js +10 -0
- package/lib/commands/monorepo/split.js +1 -1
- package/lib/commands/upgrade/2.0.d.ts +43 -0
- package/lib/commands/upgrade/2.0.js +128 -2
- package/lib/steps/gen-ext-scaffolder.d.ts +5 -0
- package/lib/steps/gen-ext-scaffolder.js +17 -2
- package/lib/steps/monorepo/split.d.ts +2 -1
- package/lib/steps/monorepo/split.js +20 -5
- package/lib/steps/stubs/backend/advanced-api-resource.js +1 -1
- package/lib/steps/stubs/backend/model-factory.d.ts +24 -0
- package/lib/steps/stubs/backend/model-factory.js +33 -0
- package/lib/steps/upgrade/twopointoh/backend/email-views.js +22 -30
- package/lib/steps/upgrade/twopointoh/backend/extension-models.d.ts +30 -0
- package/lib/steps/upgrade/twopointoh/backend/extension-models.js +34 -0
- package/lib/steps/upgrade/twopointoh/backend/json-api.d.ts +6 -0
- package/lib/steps/upgrade/twopointoh/backend/json-api.js +14 -0
- package/lib/steps/upgrade/twopointoh/backend/misc.d.ts +6 -0
- package/lib/steps/upgrade/twopointoh/backend/misc.js +19 -7
- package/lib/steps/upgrade/twopointoh/backend/model-factories.d.ts +18 -0
- package/lib/steps/upgrade/twopointoh/backend/model-factories.js +73 -0
- package/lib/steps/upgrade/twopointoh/backend/phpunit-xml.d.ts +8 -0
- package/lib/steps/upgrade/twopointoh/backend/phpunit-xml.js +33 -0
- package/lib/steps/upgrade/twopointoh/backend/phpunit.d.ts +2 -0
- package/lib/steps/upgrade/twopointoh/backend/phpunit.js +34 -21
- package/lib/steps/upgrade/twopointoh/backend/search.d.ts +9 -0
- package/lib/steps/upgrade/twopointoh/backend/search.js +28 -10
- package/lib/steps/upgrade/twopointoh/base.d.ts +38 -0
- package/lib/steps/upgrade/twopointoh/base.js +122 -24
- package/lib/steps/upgrade/twopointoh/dependencies.d.ts +58 -1
- package/lib/steps/upgrade/twopointoh/dependencies.js +343 -15
- package/lib/steps/upgrade/twopointoh/frontend/admin-extender.d.ts +86 -0
- package/lib/steps/upgrade/twopointoh/frontend/admin-extender.js +842 -0
- package/lib/steps/upgrade/twopointoh/frontend/code-splitting/usage-of-lazy-modules.js +110 -18
- package/lib/steps/upgrade/twopointoh/frontend/export-registry/import-ext.js +13 -16
- package/lib/steps/upgrade/twopointoh/frontend/misc.d.ts +23 -0
- package/lib/steps/upgrade/twopointoh/frontend/misc.js +147 -8
- package/lib/steps/upgrade/twopointoh/infra.d.ts +16 -1
- package/lib/steps/upgrade/twopointoh/infra.js +87 -5
- package/lib/steps/upgrade/twopointoh/step-failures.d.ts +32 -0
- package/lib/steps/upgrade/twopointoh/step-failures.js +54 -0
- package/lib/steps/upgrade/twopointoh/todos.d.ts +22 -0
- package/lib/steps/upgrade/twopointoh/todos.js +57 -0
- package/lib/steps/upgrade/twopointoh/typescript-4-9.d.ts +12 -0
- package/lib/steps/upgrade/twopointoh/typescript-4-9.js +200 -0
- package/lib/utils/ast.js +5 -10
- package/lib/utils/babel-ts.d.ts +9 -0
- package/lib/utils/babel-ts.js +18 -0
- package/lib/utils/composer.d.ts +5 -0
- package/lib/utils/composer.js +10 -1
- package/lib/utils/terminal.d.ts +13 -0
- package/lib/utils/terminal.js +26 -0
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/php-subsystem/index.php +12 -0
- package/php-subsystem/src/NodeUtil.php +19 -9
- package/php-subsystem/src/NodeVisitors/AddExtender.php +49 -1
- package/php-subsystem/src/Upgrade/TwoPointOh/JsonApi.php +2 -20
- package/php-subsystem/src/Upgrade/TwoPointOh/Misc.php +13 -17
- package/php-subsystem/src/Upgrade/TwoPointOh/ModelFactories.php +943 -0
- package/php-subsystem/src/Upgrade/TwoPointOh/PhpUnit.php +476 -71
- package/php-subsystem/src/Upgrade/TwoPointOh/Search.php +97 -13
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type Failure = {
|
|
2
|
+
file: string;
|
|
3
|
+
reason: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* The files a single upgrade step could not transform.
|
|
7
|
+
*
|
|
8
|
+
* A step runs over every matching file in an extension, and any one of them
|
|
9
|
+
* can defeat it — a parser that doesn't recognise some syntax, a transformer
|
|
10
|
+
* meeting a shape it wasn't written for. Collecting those instead of throwing
|
|
11
|
+
* at the first means the author is told about all of them at once, and fixes
|
|
12
|
+
* them in one pass rather than rediscovering them one re-run at a time.
|
|
13
|
+
*/
|
|
14
|
+
export declare class StepFailures {
|
|
15
|
+
private failures;
|
|
16
|
+
record(file: string, error: unknown): void;
|
|
17
|
+
any(): boolean;
|
|
18
|
+
count(): number;
|
|
19
|
+
/**
|
|
20
|
+
* The failures as data, for a program driving the upgrade.
|
|
21
|
+
*/
|
|
22
|
+
list(): Failure[];
|
|
23
|
+
/**
|
|
24
|
+
* The failures, formatted for the author: which file, and why.
|
|
25
|
+
*/
|
|
26
|
+
report(): string;
|
|
27
|
+
/**
|
|
28
|
+
* The message alone. A stack trace is about our internals, not about the
|
|
29
|
+
* code being upgraded, so it isn't what the author needs to see.
|
|
30
|
+
*/
|
|
31
|
+
private static reasonFor;
|
|
32
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StepFailures = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
|
+
/**
|
|
7
|
+
* The files a single upgrade step could not transform.
|
|
8
|
+
*
|
|
9
|
+
* A step runs over every matching file in an extension, and any one of them
|
|
10
|
+
* can defeat it — a parser that doesn't recognise some syntax, a transformer
|
|
11
|
+
* meeting a shape it wasn't written for. Collecting those instead of throwing
|
|
12
|
+
* at the first means the author is told about all of them at once, and fixes
|
|
13
|
+
* them in one pass rather than rediscovering them one re-run at a time.
|
|
14
|
+
*/
|
|
15
|
+
class StepFailures {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.failures = [];
|
|
18
|
+
}
|
|
19
|
+
record(file, error) {
|
|
20
|
+
this.failures.push({ file, reason: StepFailures.reasonFor(error) });
|
|
21
|
+
}
|
|
22
|
+
any() {
|
|
23
|
+
return this.failures.length > 0;
|
|
24
|
+
}
|
|
25
|
+
count() {
|
|
26
|
+
return this.failures.length;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The failures as data, for a program driving the upgrade.
|
|
30
|
+
*/
|
|
31
|
+
list() {
|
|
32
|
+
return this.failures.map((failure) => (Object.assign({}, failure)));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The failures, formatted for the author: which file, and why.
|
|
36
|
+
*/
|
|
37
|
+
report() {
|
|
38
|
+
return this.failures.map(({ file, reason }) => ` ${chalk_1.default.bold(file)}\n ${reason}`).join('\n\n');
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The message alone. A stack trace is about our internals, not about the
|
|
42
|
+
* code being upgraded, so it isn't what the author needs to see.
|
|
43
|
+
*/
|
|
44
|
+
static reasonFor(error) {
|
|
45
|
+
if (error instanceof Error) {
|
|
46
|
+
return error.message;
|
|
47
|
+
}
|
|
48
|
+
if (typeof error === 'string') {
|
|
49
|
+
return error;
|
|
50
|
+
}
|
|
51
|
+
return JSON.stringify(error);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.StepFailures = StepFailures;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The marker the upgrade leaves on code it could not change itself.
|
|
3
|
+
*/
|
|
4
|
+
export declare const TODO_MARKER = "@TODO";
|
|
5
|
+
export type Todo = {
|
|
6
|
+
file: string;
|
|
7
|
+
/** Null for work a step leaves without a @TODO comment in the file to show for it. */
|
|
8
|
+
line: number | null;
|
|
9
|
+
text: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The TODOs a diff adds, from `git show --unified=0`.
|
|
13
|
+
*
|
|
14
|
+
* A line that is only reformatted or moved shows up as removed and added
|
|
15
|
+
* again. When the same text was removed from the file, the TODO isn't new, so
|
|
16
|
+
* an extension's own TODOs aren't reported as work the upgrade left.
|
|
17
|
+
*/
|
|
18
|
+
export declare function todosInDiff(diff: string): Todo[];
|
|
19
|
+
/**
|
|
20
|
+
* The TODOs a commit added.
|
|
21
|
+
*/
|
|
22
|
+
export declare function todosAddedBy(dir: string, commit: string): Promise<Todo[]>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.todosAddedBy = exports.todosInDiff = exports.TODO_MARKER = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const simple_git_1 = tslib_1.__importDefault(require("simple-git"));
|
|
6
|
+
/**
|
|
7
|
+
* The marker the upgrade leaves on code it could not change itself.
|
|
8
|
+
*/
|
|
9
|
+
exports.TODO_MARKER = '@TODO';
|
|
10
|
+
/**
|
|
11
|
+
* The TODOs a diff adds, from `git show --unified=0`.
|
|
12
|
+
*
|
|
13
|
+
* A line that is only reformatted or moved shows up as removed and added
|
|
14
|
+
* again. When the same text was removed from the file, the TODO isn't new, so
|
|
15
|
+
* an extension's own TODOs aren't reported as work the upgrade left.
|
|
16
|
+
*/
|
|
17
|
+
function todosInDiff(diff) {
|
|
18
|
+
var _a;
|
|
19
|
+
const added = [];
|
|
20
|
+
const removed = new Map();
|
|
21
|
+
let file = null;
|
|
22
|
+
let line = 0;
|
|
23
|
+
for (const row of diff.split('\n')) {
|
|
24
|
+
if (row.startsWith('+++ ')) {
|
|
25
|
+
file = row === '+++ /dev/null' ? null : row.slice(4).replace(/^b\//, '');
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (row.startsWith('--- '))
|
|
29
|
+
continue;
|
|
30
|
+
const hunk = row.match(/^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/);
|
|
31
|
+
if (hunk) {
|
|
32
|
+
line = Number(hunk[1]);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (file === null)
|
|
36
|
+
continue;
|
|
37
|
+
if (row.startsWith('+')) {
|
|
38
|
+
if (row.includes(exports.TODO_MARKER)) {
|
|
39
|
+
added.push({ file, line, text: row.slice(1).trim() });
|
|
40
|
+
}
|
|
41
|
+
line++;
|
|
42
|
+
}
|
|
43
|
+
else if (row.startsWith('-')) {
|
|
44
|
+
removed.set(file, [...((_a = removed.get(file)) !== null && _a !== void 0 ? _a : []), row.slice(1).trim()]);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return added.filter((todo) => { var _a; return !((_a = removed.get(todo.file)) === null || _a === void 0 ? void 0 : _a.includes(todo.text)); });
|
|
48
|
+
}
|
|
49
|
+
exports.todosInDiff = todosInDiff;
|
|
50
|
+
/**
|
|
51
|
+
* The TODOs a commit added.
|
|
52
|
+
*/
|
|
53
|
+
async function todosAddedBy(dir, commit) {
|
|
54
|
+
const diff = await (0, simple_git_1.default)(dir).show([commit, '--format=', '--unified=0', '--no-color', '--no-ext-diff', '--no-renames']);
|
|
55
|
+
return todosInDiff(diff);
|
|
56
|
+
}
|
|
57
|
+
exports.todosAddedBy = todosAddedBy;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The compiler options TypeScript 4.9 knows, which Flarum 2.0 builds with, and
|
|
3
|
+
* the values it accepts for those that take one of a set. A tsconfig.json has
|
|
4
|
+
* to spell an option exactly so; its values may be in any case, so they are
|
|
5
|
+
* listed lowercase.
|
|
6
|
+
*
|
|
7
|
+
* Generated from typescript@4.9.5: `ts.optionDeclarations`, each name mapped
|
|
8
|
+
* to true, or to the keys of its type when that is a Map; the libs are the
|
|
9
|
+
* keys of the `lib` option's element type.
|
|
10
|
+
*/
|
|
11
|
+
export declare const compilerOptions: Record<string, true | string[]>;
|
|
12
|
+
export declare const libs: string[];
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.libs = exports.compilerOptions = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The compiler options TypeScript 4.9 knows, which Flarum 2.0 builds with, and
|
|
6
|
+
* the values it accepts for those that take one of a set. A tsconfig.json has
|
|
7
|
+
* to spell an option exactly so; its values may be in any case, so they are
|
|
8
|
+
* listed lowercase.
|
|
9
|
+
*
|
|
10
|
+
* Generated from typescript@4.9.5: `ts.optionDeclarations`, each name mapped
|
|
11
|
+
* to true, or to the keys of its type when that is a Map; the libs are the
|
|
12
|
+
* keys of the `lib` option's element type.
|
|
13
|
+
*/
|
|
14
|
+
exports.compilerOptions = {
|
|
15
|
+
all: true,
|
|
16
|
+
allowJs: true,
|
|
17
|
+
allowSyntheticDefaultImports: true,
|
|
18
|
+
allowUmdGlobalAccess: true,
|
|
19
|
+
allowUnreachableCode: true,
|
|
20
|
+
allowUnusedLabels: true,
|
|
21
|
+
alwaysStrict: true,
|
|
22
|
+
assumeChangesOnlyAffectDirectDependencies: true,
|
|
23
|
+
baseUrl: true,
|
|
24
|
+
build: true,
|
|
25
|
+
charset: true,
|
|
26
|
+
checkJs: true,
|
|
27
|
+
composite: true,
|
|
28
|
+
declaration: true,
|
|
29
|
+
declarationDir: true,
|
|
30
|
+
declarationMap: true,
|
|
31
|
+
diagnostics: true,
|
|
32
|
+
disableReferencedProjectLoad: true,
|
|
33
|
+
disableSizeLimit: true,
|
|
34
|
+
disableSolutionSearching: true,
|
|
35
|
+
disableSourceOfProjectReferenceRedirect: true,
|
|
36
|
+
downlevelIteration: true,
|
|
37
|
+
emitBOM: true,
|
|
38
|
+
emitDeclarationOnly: true,
|
|
39
|
+
emitDecoratorMetadata: true,
|
|
40
|
+
esModuleInterop: true,
|
|
41
|
+
exactOptionalPropertyTypes: true,
|
|
42
|
+
experimentalDecorators: true,
|
|
43
|
+
explainFiles: true,
|
|
44
|
+
extendedDiagnostics: true,
|
|
45
|
+
forceConsistentCasingInFileNames: true,
|
|
46
|
+
generateCpuProfile: true,
|
|
47
|
+
generateTrace: true,
|
|
48
|
+
help: true,
|
|
49
|
+
ignoreDeprecations: true,
|
|
50
|
+
importHelpers: true,
|
|
51
|
+
importsNotUsedAsValues: ['error', 'preserve', 'remove'],
|
|
52
|
+
incremental: true,
|
|
53
|
+
init: true,
|
|
54
|
+
inlineSourceMap: true,
|
|
55
|
+
inlineSources: true,
|
|
56
|
+
isolatedModules: true,
|
|
57
|
+
jsx: ['preserve', 'react', 'react-jsx', 'react-jsxdev', 'react-native'],
|
|
58
|
+
jsxFactory: true,
|
|
59
|
+
jsxFragmentFactory: true,
|
|
60
|
+
jsxImportSource: true,
|
|
61
|
+
keyofStringsOnly: true,
|
|
62
|
+
lib: true,
|
|
63
|
+
listEmittedFiles: true,
|
|
64
|
+
listFiles: true,
|
|
65
|
+
listFilesOnly: true,
|
|
66
|
+
locale: true,
|
|
67
|
+
mapRoot: true,
|
|
68
|
+
maxNodeModuleJsDepth: true,
|
|
69
|
+
module: ['amd', 'commonjs', 'es2015', 'es2020', 'es2022', 'es6', 'esnext', 'node16', 'nodenext', 'none', 'system', 'umd'],
|
|
70
|
+
moduleDetection: ['auto', 'force', 'legacy'],
|
|
71
|
+
moduleResolution: ['classic', 'node', 'node16', 'nodenext'],
|
|
72
|
+
moduleSuffixes: true,
|
|
73
|
+
newLine: ['crlf', 'lf'],
|
|
74
|
+
noEmit: true,
|
|
75
|
+
noEmitHelpers: true,
|
|
76
|
+
noEmitOnError: true,
|
|
77
|
+
noErrorTruncation: true,
|
|
78
|
+
noFallthroughCasesInSwitch: true,
|
|
79
|
+
noImplicitAny: true,
|
|
80
|
+
noImplicitOverride: true,
|
|
81
|
+
noImplicitReturns: true,
|
|
82
|
+
noImplicitThis: true,
|
|
83
|
+
noImplicitUseStrict: true,
|
|
84
|
+
noLib: true,
|
|
85
|
+
noPropertyAccessFromIndexSignature: true,
|
|
86
|
+
noResolve: true,
|
|
87
|
+
noStrictGenericChecks: true,
|
|
88
|
+
noUncheckedIndexedAccess: true,
|
|
89
|
+
noUnusedLocals: true,
|
|
90
|
+
noUnusedParameters: true,
|
|
91
|
+
out: true,
|
|
92
|
+
outDir: true,
|
|
93
|
+
outFile: true,
|
|
94
|
+
paths: true,
|
|
95
|
+
plugins: true,
|
|
96
|
+
preserveConstEnums: true,
|
|
97
|
+
preserveSymlinks: true,
|
|
98
|
+
preserveValueImports: true,
|
|
99
|
+
preserveWatchOutput: true,
|
|
100
|
+
pretty: true,
|
|
101
|
+
project: true,
|
|
102
|
+
reactNamespace: true,
|
|
103
|
+
removeComments: true,
|
|
104
|
+
resolveJsonModule: true,
|
|
105
|
+
rootDir: true,
|
|
106
|
+
rootDirs: true,
|
|
107
|
+
showConfig: true,
|
|
108
|
+
skipDefaultLibCheck: true,
|
|
109
|
+
skipLibCheck: true,
|
|
110
|
+
sourceMap: true,
|
|
111
|
+
sourceRoot: true,
|
|
112
|
+
strict: true,
|
|
113
|
+
strictBindCallApply: true,
|
|
114
|
+
strictFunctionTypes: true,
|
|
115
|
+
strictNullChecks: true,
|
|
116
|
+
strictPropertyInitialization: true,
|
|
117
|
+
stripInternal: true,
|
|
118
|
+
suppressExcessPropertyErrors: true,
|
|
119
|
+
suppressImplicitAnyIndexErrors: true,
|
|
120
|
+
target: ['es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'es3', 'es5', 'es6', 'esnext'],
|
|
121
|
+
traceResolution: true,
|
|
122
|
+
tsBuildInfoFile: true,
|
|
123
|
+
typeRoots: true,
|
|
124
|
+
types: true,
|
|
125
|
+
useDefineForClassFields: true,
|
|
126
|
+
useUnknownInCatchVariables: true,
|
|
127
|
+
version: true,
|
|
128
|
+
watch: true,
|
|
129
|
+
};
|
|
130
|
+
exports.libs = [
|
|
131
|
+
'dom',
|
|
132
|
+
'dom.iterable',
|
|
133
|
+
'es2015',
|
|
134
|
+
'es2015.collection',
|
|
135
|
+
'es2015.core',
|
|
136
|
+
'es2015.generator',
|
|
137
|
+
'es2015.iterable',
|
|
138
|
+
'es2015.promise',
|
|
139
|
+
'es2015.proxy',
|
|
140
|
+
'es2015.reflect',
|
|
141
|
+
'es2015.symbol',
|
|
142
|
+
'es2015.symbol.wellknown',
|
|
143
|
+
'es2016',
|
|
144
|
+
'es2016.array.include',
|
|
145
|
+
'es2017',
|
|
146
|
+
'es2017.intl',
|
|
147
|
+
'es2017.object',
|
|
148
|
+
'es2017.sharedmemory',
|
|
149
|
+
'es2017.string',
|
|
150
|
+
'es2017.typedarrays',
|
|
151
|
+
'es2018',
|
|
152
|
+
'es2018.asyncgenerator',
|
|
153
|
+
'es2018.asynciterable',
|
|
154
|
+
'es2018.intl',
|
|
155
|
+
'es2018.promise',
|
|
156
|
+
'es2018.regexp',
|
|
157
|
+
'es2019',
|
|
158
|
+
'es2019.array',
|
|
159
|
+
'es2019.intl',
|
|
160
|
+
'es2019.object',
|
|
161
|
+
'es2019.string',
|
|
162
|
+
'es2019.symbol',
|
|
163
|
+
'es2020',
|
|
164
|
+
'es2020.bigint',
|
|
165
|
+
'es2020.date',
|
|
166
|
+
'es2020.intl',
|
|
167
|
+
'es2020.number',
|
|
168
|
+
'es2020.promise',
|
|
169
|
+
'es2020.sharedmemory',
|
|
170
|
+
'es2020.string',
|
|
171
|
+
'es2020.symbol.wellknown',
|
|
172
|
+
'es2021',
|
|
173
|
+
'es2021.intl',
|
|
174
|
+
'es2021.promise',
|
|
175
|
+
'es2021.string',
|
|
176
|
+
'es2021.weakref',
|
|
177
|
+
'es2022',
|
|
178
|
+
'es2022.array',
|
|
179
|
+
'es2022.error',
|
|
180
|
+
'es2022.intl',
|
|
181
|
+
'es2022.object',
|
|
182
|
+
'es2022.sharedmemory',
|
|
183
|
+
'es2022.string',
|
|
184
|
+
'es5',
|
|
185
|
+
'es6',
|
|
186
|
+
'es7',
|
|
187
|
+
'esnext',
|
|
188
|
+
'esnext.array',
|
|
189
|
+
'esnext.asynciterable',
|
|
190
|
+
'esnext.bigint',
|
|
191
|
+
'esnext.intl',
|
|
192
|
+
'esnext.promise',
|
|
193
|
+
'esnext.string',
|
|
194
|
+
'esnext.symbol',
|
|
195
|
+
'esnext.weakref',
|
|
196
|
+
'scripthost',
|
|
197
|
+
'webworker',
|
|
198
|
+
'webworker.importscripts',
|
|
199
|
+
'webworker.iterable',
|
|
200
|
+
];
|
package/lib/utils/ast.js
CHANGED
|
@@ -9,22 +9,17 @@ const prettierrc_json_1 = tslib_1.__importDefault(require("@flarum/prettier-conf
|
|
|
9
9
|
// import { parse } from '@babel/parser';
|
|
10
10
|
// import generate from '@babel/generator';
|
|
11
11
|
const recast = tslib_1.__importStar(require("recast"));
|
|
12
|
+
const babelTs = tslib_1.__importStar(require("./babel-ts"));
|
|
12
13
|
function parseCode(code) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
console.log(code);
|
|
20
|
-
throw error;
|
|
21
|
-
}
|
|
14
|
+
return recast.parse(code, {
|
|
15
|
+
parser: babelTs,
|
|
16
|
+
});
|
|
22
17
|
}
|
|
23
18
|
exports.parseCode = parseCode;
|
|
24
19
|
async function generateCode(ast, extenders = false) {
|
|
25
20
|
// @ts-ignore
|
|
26
21
|
const generatedCode = recast.print(ast, {
|
|
27
|
-
parser:
|
|
22
|
+
parser: babelTs,
|
|
28
23
|
}).code;
|
|
29
24
|
// Format the code
|
|
30
25
|
return formatCode(generatedCode, extenders);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ParseResult } from '@babel/parser';
|
|
2
|
+
import * as t from '@babel/types';
|
|
3
|
+
/**
|
|
4
|
+
* Recast's babel-ts parser, which also accepts an export of a name it can't see
|
|
5
|
+
* declared, as Prettier does. Babel reports one for every `export { name }` in
|
|
6
|
+
* an ambient `declare module` block, which is valid TypeScript. The upgrade
|
|
7
|
+
* rewrites code rather than checking it: the extension's own build does that.
|
|
8
|
+
*/
|
|
9
|
+
export declare function parse(source: string): ParseResult<t.File>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parse = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const parser_1 = require("@babel/parser");
|
|
6
|
+
const _babel_options_1 = tslib_1.__importDefault(require("recast/parsers/_babel_options"));
|
|
7
|
+
/**
|
|
8
|
+
* Recast's babel-ts parser, which also accepts an export of a name it can't see
|
|
9
|
+
* declared, as Prettier does. Babel reports one for every `export { name }` in
|
|
10
|
+
* an ambient `declare module` block, which is valid TypeScript. The upgrade
|
|
11
|
+
* rewrites code rather than checking it: the extension's own build does that.
|
|
12
|
+
*/
|
|
13
|
+
function parse(source) {
|
|
14
|
+
const options = (0, _babel_options_1.default)();
|
|
15
|
+
options.plugins.push('jsx', 'typescript');
|
|
16
|
+
return (0, parser_1.parse)(source, Object.assign(Object.assign({}, options), { allowUndeclaredExports: true }));
|
|
17
|
+
}
|
|
18
|
+
exports.parse = parse;
|
package/lib/utils/composer.d.ts
CHANGED
|
@@ -63,3 +63,8 @@ export type ComposerJsonSchema = {
|
|
|
63
63
|
};
|
|
64
64
|
};
|
|
65
65
|
export declare function getComposerJson(fs: Store, paths: Paths): ComposerJsonSchema;
|
|
66
|
+
/**
|
|
67
|
+
* An extension's ID, from its package name, as core makes it: `vendor-package`,
|
|
68
|
+
* without a `flarum-ext-` or `flarum-` in the package's part.
|
|
69
|
+
*/
|
|
70
|
+
export declare function extensionId(packageName: string): string;
|
package/lib/utils/composer.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getComposerJson = void 0;
|
|
3
|
+
exports.extensionId = exports.getComposerJson = void 0;
|
|
4
4
|
const mem_fs_editor_1 = require("mem-fs-editor");
|
|
5
5
|
function getComposerJson(fs, paths) {
|
|
6
6
|
return (0, mem_fs_editor_1.create)(fs).readJSON(paths.package('composer.json'));
|
|
7
7
|
}
|
|
8
8
|
exports.getComposerJson = getComposerJson;
|
|
9
|
+
/**
|
|
10
|
+
* An extension's ID, from its package name, as core makes it: `vendor-package`,
|
|
11
|
+
* without a `flarum-ext-` or `flarum-` in the package's part.
|
|
12
|
+
*/
|
|
13
|
+
function extensionId(packageName) {
|
|
14
|
+
const [vendor, pkg] = packageName.includes('/') ? packageName.split('/', 2) : [packageName, packageName];
|
|
15
|
+
return `${vendor}-${pkg.replace(/flarum-ext-/g, '').replace(/flarum-/g, '')}`;
|
|
16
|
+
}
|
|
17
|
+
exports.extensionId = extensionId;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether output goes to a terminal, rather than to a file or another program.
|
|
3
|
+
*/
|
|
4
|
+
export declare function isTerminal(): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Moves the cursor up a line, so the next one overwrites it. Only in a
|
|
7
|
+
* terminal: anywhere else the escape code is noise.
|
|
8
|
+
*/
|
|
9
|
+
export declare function overwrite(): string;
|
|
10
|
+
/**
|
|
11
|
+
* The text without colours or cursor movement.
|
|
12
|
+
*/
|
|
13
|
+
export declare function stripAnsi(text: string): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stripAnsi = exports.overwrite = exports.isTerminal = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Whether output goes to a terminal, rather than to a file or another program.
|
|
6
|
+
*/
|
|
7
|
+
function isTerminal() {
|
|
8
|
+
return Boolean(process.stdout.isTTY);
|
|
9
|
+
}
|
|
10
|
+
exports.isTerminal = isTerminal;
|
|
11
|
+
/**
|
|
12
|
+
* Moves the cursor up a line, so the next one overwrites it. Only in a
|
|
13
|
+
* terminal: anywhere else the escape code is noise.
|
|
14
|
+
*/
|
|
15
|
+
function overwrite() {
|
|
16
|
+
return isTerminal() ? '\u001B[A' : '';
|
|
17
|
+
}
|
|
18
|
+
exports.overwrite = overwrite;
|
|
19
|
+
/**
|
|
20
|
+
* The text without colours or cursor movement.
|
|
21
|
+
*/
|
|
22
|
+
function stripAnsi(text) {
|
|
23
|
+
// eslint-disable-next-line no-control-regex
|
|
24
|
+
return text.replace(/\u001B\[[\d;]*[A-Za-z]/g, '');
|
|
25
|
+
}
|
|
26
|
+
exports.stripAnsi = stripAnsi;
|