@flarum/cli 3.0.12 → 3.0.14

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.
Files changed (66) hide show
  1. package/README.md +33 -1
  2. package/boilerplate/skeleton/extension/composer.json +4 -0
  3. package/boilerplate/skeleton/extension/js/package.json +5 -5
  4. package/boilerplate/skeleton/extension/js/tsconfig.json +3 -0
  5. package/boilerplate/skeleton/extension/js/tsconfig.test.json +1 -0
  6. package/boilerplate/stubs/backend/advanced-api-resource.php +3 -3
  7. package/boilerplate/stubs/backend/model-factory.php +17 -0
  8. package/boilerplate/stubs/backend/model.php +3 -0
  9. package/lib/base-command.d.ts +21 -3
  10. package/lib/base-command.js +52 -5
  11. package/lib/commands/make/backend/model.js +10 -0
  12. package/lib/commands/upgrade/2.0.d.ts +43 -0
  13. package/lib/commands/upgrade/2.0.js +128 -2
  14. package/lib/steps/gen-ext-scaffolder.d.ts +5 -0
  15. package/lib/steps/gen-ext-scaffolder.js +17 -2
  16. package/lib/steps/stubs/backend/advanced-api-resource.js +1 -1
  17. package/lib/steps/stubs/backend/model-factory.d.ts +24 -0
  18. package/lib/steps/stubs/backend/model-factory.js +33 -0
  19. package/lib/steps/upgrade/twopointoh/backend/email-views.js +22 -30
  20. package/lib/steps/upgrade/twopointoh/backend/extension-models.d.ts +30 -0
  21. package/lib/steps/upgrade/twopointoh/backend/extension-models.js +34 -0
  22. package/lib/steps/upgrade/twopointoh/backend/json-api.d.ts +6 -0
  23. package/lib/steps/upgrade/twopointoh/backend/json-api.js +14 -0
  24. package/lib/steps/upgrade/twopointoh/backend/misc.d.ts +6 -0
  25. package/lib/steps/upgrade/twopointoh/backend/misc.js +19 -7
  26. package/lib/steps/upgrade/twopointoh/backend/model-factories.d.ts +18 -0
  27. package/lib/steps/upgrade/twopointoh/backend/model-factories.js +73 -0
  28. package/lib/steps/upgrade/twopointoh/backend/phpunit.d.ts +2 -0
  29. package/lib/steps/upgrade/twopointoh/backend/phpunit.js +16 -8
  30. package/lib/steps/upgrade/twopointoh/backend/search.d.ts +9 -0
  31. package/lib/steps/upgrade/twopointoh/backend/search.js +28 -10
  32. package/lib/steps/upgrade/twopointoh/base.d.ts +38 -0
  33. package/lib/steps/upgrade/twopointoh/base.js +73 -12
  34. package/lib/steps/upgrade/twopointoh/dependencies.d.ts +55 -0
  35. package/lib/steps/upgrade/twopointoh/dependencies.js +317 -20
  36. package/lib/steps/upgrade/twopointoh/frontend/admin-extender.d.ts +86 -0
  37. package/lib/steps/upgrade/twopointoh/frontend/admin-extender.js +842 -0
  38. package/lib/steps/upgrade/twopointoh/frontend/code-splitting/usage-of-lazy-modules.js +110 -18
  39. package/lib/steps/upgrade/twopointoh/frontend/export-registry/import-ext.js +13 -16
  40. package/lib/steps/upgrade/twopointoh/frontend/misc.d.ts +23 -0
  41. package/lib/steps/upgrade/twopointoh/frontend/misc.js +147 -8
  42. package/lib/steps/upgrade/twopointoh/infra.d.ts +16 -1
  43. package/lib/steps/upgrade/twopointoh/infra.js +87 -5
  44. package/lib/steps/upgrade/twopointoh/step-failures.d.ts +8 -0
  45. package/lib/steps/upgrade/twopointoh/step-failures.js +6 -0
  46. package/lib/steps/upgrade/twopointoh/todos.d.ts +22 -0
  47. package/lib/steps/upgrade/twopointoh/todos.js +57 -0
  48. package/lib/steps/upgrade/twopointoh/typescript-5-9.d.ts +15 -0
  49. package/lib/steps/upgrade/twopointoh/typescript-5-9.js +250 -0
  50. package/lib/utils/ast.js +3 -2
  51. package/lib/utils/babel-ts.d.ts +9 -0
  52. package/lib/utils/babel-ts.js +18 -0
  53. package/lib/utils/composer.d.ts +5 -0
  54. package/lib/utils/composer.js +10 -1
  55. package/lib/utils/terminal.d.ts +13 -0
  56. package/lib/utils/terminal.js +26 -0
  57. package/oclif.manifest.json +1 -1
  58. package/package.json +1 -1
  59. package/php-subsystem/index.php +12 -0
  60. package/php-subsystem/src/NodeUtil.php +19 -9
  61. package/php-subsystem/src/NodeVisitors/AddExtender.php +49 -1
  62. package/php-subsystem/src/Upgrade/TwoPointOh/JsonApi.php +2 -20
  63. package/php-subsystem/src/Upgrade/TwoPointOh/Misc.php +13 -17
  64. package/php-subsystem/src/Upgrade/TwoPointOh/ModelFactories.php +943 -0
  65. package/php-subsystem/src/Upgrade/TwoPointOh/PhpUnit.php +476 -71
  66. package/php-subsystem/src/Upgrade/TwoPointOh/Search.php +97 -13
@@ -1,3 +1,7 @@
1
+ export type Failure = {
2
+ file: string;
3
+ reason: string;
4
+ };
1
5
  /**
2
6
  * The files a single upgrade step could not transform.
3
7
  *
@@ -12,6 +16,10 @@ export declare class StepFailures {
12
16
  record(file: string, error: unknown): void;
13
17
  any(): boolean;
14
18
  count(): number;
19
+ /**
20
+ * The failures as data, for a program driving the upgrade.
21
+ */
22
+ list(): Failure[];
15
23
  /**
16
24
  * The failures, formatted for the author: which file, and why.
17
25
  */
@@ -25,6 +25,12 @@ class StepFailures {
25
25
  count() {
26
26
  return this.failures.length;
27
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
+ }
28
34
  /**
29
35
  * The failures, formatted for the author: which file, and why.
30
36
  */
@@ -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,15 @@
1
+ /**
2
+ * The compiler options TypeScript 5.9 accepts, which Flarum 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@5.9.3: `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. Left out are the options and values
10
+ * 5.9 still declares but refuses, as TypeScript 5.5 removed them:
11
+ * charset, importsNotUsedAsValues, keyofStringsOnly, noImplicitUseStrict, noStrictGenericChecks, out, preserveValueImports, suppressExcessPropertyErrors, suppressImplicitAnyIndexErrors,
12
+ * and target ES3.
13
+ */
14
+ export declare const compilerOptions: Record<string, true | string[]>;
15
+ export declare const libs: string[];
@@ -0,0 +1,250 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.libs = exports.compilerOptions = void 0;
4
+ /**
5
+ * The compiler options TypeScript 5.9 accepts, which Flarum 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@5.9.3: `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. Left out are the options and values
13
+ * 5.9 still declares but refuses, as TypeScript 5.5 removed them:
14
+ * charset, importsNotUsedAsValues, keyofStringsOnly, noImplicitUseStrict, noStrictGenericChecks, out, preserveValueImports, suppressExcessPropertyErrors, suppressImplicitAnyIndexErrors,
15
+ * and target ES3.
16
+ */
17
+ exports.compilerOptions = {
18
+ all: true,
19
+ allowArbitraryExtensions: true,
20
+ allowImportingTsExtensions: true,
21
+ allowJs: true,
22
+ allowSyntheticDefaultImports: true,
23
+ allowUmdGlobalAccess: true,
24
+ allowUnreachableCode: true,
25
+ allowUnusedLabels: true,
26
+ alwaysStrict: true,
27
+ assumeChangesOnlyAffectDirectDependencies: true,
28
+ baseUrl: true,
29
+ checkJs: true,
30
+ composite: true,
31
+ customConditions: true,
32
+ declaration: true,
33
+ declarationDir: true,
34
+ declarationMap: true,
35
+ diagnostics: true,
36
+ disableReferencedProjectLoad: true,
37
+ disableSizeLimit: true,
38
+ disableSolutionSearching: true,
39
+ disableSourceOfProjectReferenceRedirect: true,
40
+ downlevelIteration: true,
41
+ emitBOM: true,
42
+ emitDeclarationOnly: true,
43
+ emitDecoratorMetadata: true,
44
+ erasableSyntaxOnly: true,
45
+ esModuleInterop: true,
46
+ exactOptionalPropertyTypes: true,
47
+ experimentalDecorators: true,
48
+ explainFiles: true,
49
+ extendedDiagnostics: true,
50
+ forceConsistentCasingInFileNames: true,
51
+ generateCpuProfile: true,
52
+ generateTrace: true,
53
+ help: true,
54
+ ignoreDeprecations: true,
55
+ importHelpers: true,
56
+ incremental: true,
57
+ init: true,
58
+ inlineSourceMap: true,
59
+ inlineSources: true,
60
+ isolatedDeclarations: true,
61
+ isolatedModules: true,
62
+ jsx: ['preserve', 'react', 'react-jsx', 'react-jsxdev', 'react-native'],
63
+ jsxFactory: true,
64
+ jsxFragmentFactory: true,
65
+ jsxImportSource: true,
66
+ lib: true,
67
+ libReplacement: true,
68
+ listEmittedFiles: true,
69
+ listFiles: true,
70
+ listFilesOnly: true,
71
+ locale: true,
72
+ mapRoot: true,
73
+ maxNodeModuleJsDepth: true,
74
+ module: [
75
+ 'amd',
76
+ 'commonjs',
77
+ 'es2015',
78
+ 'es2020',
79
+ 'es2022',
80
+ 'es6',
81
+ 'esnext',
82
+ 'node16',
83
+ 'node18',
84
+ 'node20',
85
+ 'nodenext',
86
+ 'none',
87
+ 'preserve',
88
+ 'system',
89
+ 'umd',
90
+ ],
91
+ moduleDetection: ['auto', 'force', 'legacy'],
92
+ moduleResolution: ['bundler', 'classic', 'node', 'node10', 'node16', 'nodenext'],
93
+ moduleSuffixes: true,
94
+ newLine: ['crlf', 'lf'],
95
+ noCheck: true,
96
+ noEmit: true,
97
+ noEmitHelpers: true,
98
+ noEmitOnError: true,
99
+ noErrorTruncation: true,
100
+ noFallthroughCasesInSwitch: true,
101
+ noImplicitAny: true,
102
+ noImplicitOverride: true,
103
+ noImplicitReturns: true,
104
+ noImplicitThis: true,
105
+ noLib: true,
106
+ noPropertyAccessFromIndexSignature: true,
107
+ noResolve: true,
108
+ noUncheckedIndexedAccess: true,
109
+ noUncheckedSideEffectImports: true,
110
+ noUnusedLocals: true,
111
+ noUnusedParameters: true,
112
+ outDir: true,
113
+ outFile: true,
114
+ paths: true,
115
+ plugins: true,
116
+ preserveConstEnums: true,
117
+ preserveSymlinks: true,
118
+ preserveWatchOutput: true,
119
+ pretty: true,
120
+ project: true,
121
+ reactNamespace: true,
122
+ removeComments: true,
123
+ resolveJsonModule: true,
124
+ resolvePackageJsonExports: true,
125
+ resolvePackageJsonImports: true,
126
+ rewriteRelativeImportExtensions: true,
127
+ rootDir: true,
128
+ rootDirs: true,
129
+ showConfig: true,
130
+ skipDefaultLibCheck: true,
131
+ skipLibCheck: true,
132
+ sourceMap: true,
133
+ sourceRoot: true,
134
+ strict: true,
135
+ strictBindCallApply: true,
136
+ strictBuiltinIteratorReturn: true,
137
+ strictFunctionTypes: true,
138
+ strictNullChecks: true,
139
+ strictPropertyInitialization: true,
140
+ stripInternal: true,
141
+ target: ['es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'es2023', 'es2024', 'es5', 'es6', 'esnext'],
142
+ traceResolution: true,
143
+ tsBuildInfoFile: true,
144
+ typeRoots: true,
145
+ types: true,
146
+ useDefineForClassFields: true,
147
+ useUnknownInCatchVariables: true,
148
+ verbatimModuleSyntax: true,
149
+ version: true,
150
+ watch: true,
151
+ };
152
+ exports.libs = [
153
+ 'decorators',
154
+ 'decorators.legacy',
155
+ 'dom',
156
+ 'dom.asynciterable',
157
+ 'dom.iterable',
158
+ 'es2015',
159
+ 'es2015.collection',
160
+ 'es2015.core',
161
+ 'es2015.generator',
162
+ 'es2015.iterable',
163
+ 'es2015.promise',
164
+ 'es2015.proxy',
165
+ 'es2015.reflect',
166
+ 'es2015.symbol',
167
+ 'es2015.symbol.wellknown',
168
+ 'es2016',
169
+ 'es2016.array.include',
170
+ 'es2016.intl',
171
+ 'es2017',
172
+ 'es2017.arraybuffer',
173
+ 'es2017.date',
174
+ 'es2017.intl',
175
+ 'es2017.object',
176
+ 'es2017.sharedmemory',
177
+ 'es2017.string',
178
+ 'es2017.typedarrays',
179
+ 'es2018',
180
+ 'es2018.asyncgenerator',
181
+ 'es2018.asynciterable',
182
+ 'es2018.intl',
183
+ 'es2018.promise',
184
+ 'es2018.regexp',
185
+ 'es2019',
186
+ 'es2019.array',
187
+ 'es2019.intl',
188
+ 'es2019.object',
189
+ 'es2019.string',
190
+ 'es2019.symbol',
191
+ 'es2020',
192
+ 'es2020.bigint',
193
+ 'es2020.date',
194
+ 'es2020.intl',
195
+ 'es2020.number',
196
+ 'es2020.promise',
197
+ 'es2020.sharedmemory',
198
+ 'es2020.string',
199
+ 'es2020.symbol.wellknown',
200
+ 'es2021',
201
+ 'es2021.intl',
202
+ 'es2021.promise',
203
+ 'es2021.string',
204
+ 'es2021.weakref',
205
+ 'es2022',
206
+ 'es2022.array',
207
+ 'es2022.error',
208
+ 'es2022.intl',
209
+ 'es2022.object',
210
+ 'es2022.regexp',
211
+ 'es2022.string',
212
+ 'es2023',
213
+ 'es2023.array',
214
+ 'es2023.collection',
215
+ 'es2023.intl',
216
+ 'es2024',
217
+ 'es2024.arraybuffer',
218
+ 'es2024.collection',
219
+ 'es2024.object',
220
+ 'es2024.promise',
221
+ 'es2024.regexp',
222
+ 'es2024.sharedmemory',
223
+ 'es2024.string',
224
+ 'es5',
225
+ 'es6',
226
+ 'es7',
227
+ 'esnext',
228
+ 'esnext.array',
229
+ 'esnext.asynciterable',
230
+ 'esnext.bigint',
231
+ 'esnext.collection',
232
+ 'esnext.decorators',
233
+ 'esnext.disposable',
234
+ 'esnext.error',
235
+ 'esnext.float16',
236
+ 'esnext.intl',
237
+ 'esnext.iterator',
238
+ 'esnext.object',
239
+ 'esnext.promise',
240
+ 'esnext.regexp',
241
+ 'esnext.sharedmemory',
242
+ 'esnext.string',
243
+ 'esnext.symbol',
244
+ 'esnext.weakref',
245
+ 'scripthost',
246
+ 'webworker',
247
+ 'webworker.asynciterable',
248
+ 'webworker.importscripts',
249
+ 'webworker.iterable',
250
+ ];
package/lib/utils/ast.js CHANGED
@@ -9,16 +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
  return recast.parse(code, {
14
- parser: require('recast/parsers/babel-ts'),
15
+ parser: babelTs,
15
16
  });
16
17
  }
17
18
  exports.parseCode = parseCode;
18
19
  async function generateCode(ast, extenders = false) {
19
20
  // @ts-ignore
20
21
  const generatedCode = recast.print(ast, {
21
- parser: require('recast/parsers/babel-ts'),
22
+ parser: babelTs,
22
23
  }).code;
23
24
  // Format the code
24
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;
@@ -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;
@@ -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;