@directus/extensions-sdk 9.23.4 → 9.25.0

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 (110) hide show
  1. package/cli.js +1 -1
  2. package/dist/{cjs/cli → cli}/commands/add.d.ts +0 -1
  3. package/dist/{esm/cli → cli}/commands/add.js +16 -18
  4. package/dist/{esm/cli → cli}/commands/build.d.ts +0 -1
  5. package/dist/{esm/cli → cli}/commands/build.js +23 -29
  6. package/dist/{cjs/cli → cli}/commands/create.d.ts +0 -1
  7. package/dist/{esm/cli → cli}/commands/create.js +12 -13
  8. package/dist/{cjs/cli → cli}/commands/helpers/copy-template.d.ts +2 -3
  9. package/dist/{esm/cli → cli}/commands/helpers/copy-template.js +2 -2
  10. package/dist/cli/commands/helpers/generate-bundle-entrypoint.d.ts +2 -0
  11. package/dist/{esm/cli → cli}/commands/helpers/generate-bundle-entrypoint.js +3 -3
  12. package/dist/{cjs/cli → cli}/commands/helpers/get-extension-dev-deps.d.ts +2 -3
  13. package/dist/{esm/cli → cli}/commands/helpers/get-extension-dev-deps.js +4 -4
  14. package/dist/cli/commands/helpers/load-config.d.ts +2 -0
  15. package/dist/{esm/cli → cli}/commands/helpers/load-config.js +2 -2
  16. package/dist/cli/commands/helpers/validate-cli-options.d.ts +2 -0
  17. package/dist/{esm/cli → cli}/commands/helpers/validate-cli-options.js +1 -1
  18. package/dist/{cjs/cli → cli}/commands/link.d.ts +0 -1
  19. package/dist/{esm/cli → cli}/commands/link.js +4 -5
  20. package/dist/cli/index.d.ts +3 -0
  21. package/dist/cli/index.js +3 -0
  22. package/dist/{esm/cli → cli}/run.js +4 -4
  23. package/dist/{esm/cli → cli}/types.d.ts +2 -3
  24. package/dist/cli/types.js +1 -0
  25. package/dist/{cjs/cli → cli}/utils/detect-json-indent.d.ts +0 -1
  26. package/dist/{esm/cli → cli}/utils/detect-json-indent.js +1 -2
  27. package/dist/{cjs/cli → cli}/utils/get-package-manager-agent.d.ts +0 -1
  28. package/dist/{esm/cli → cli}/utils/get-package-manager-agent.js +1 -1
  29. package/dist/cli/utils/get-package-manager-agent.test.d.ts +1 -0
  30. package/dist/{esm/cli → cli}/utils/get-package-manager-agent.test.js +3 -3
  31. package/dist/{cjs/cli → cli}/utils/get-package-manager.d.ts +0 -1
  32. package/dist/{esm/cli → cli}/utils/get-package-manager.js +3 -3
  33. package/dist/cli/utils/get-package-manager.test.d.ts +1 -0
  34. package/dist/{esm/cli → cli}/utils/get-package-manager.test.js +3 -3
  35. package/dist/{cjs/cli → cli}/utils/get-package-version.d.ts +0 -1
  36. package/dist/{cjs/cli → cli}/utils/get-sdk-version.d.ts +0 -1
  37. package/dist/cli/utils/get-sdk-version.js +8 -0
  38. package/dist/{cjs/cli → cli}/utils/get-template-path.d.ts +0 -1
  39. package/dist/{cjs/cli → cli}/utils/languages.d.ts +1 -2
  40. package/dist/{esm/cli → cli}/utils/languages.js +1 -1
  41. package/dist/{cjs/cli → cli}/utils/logger.d.ts +0 -1
  42. package/dist/cli/utils/try-parse-json.d.ts +2 -0
  43. package/dist/{cjs/index.d.ts → index.d.ts} +2 -3
  44. package/dist/{esm/index.js → index.js} +2 -2
  45. package/package.json +14 -25
  46. package/dist/cjs/cli/commands/add.js +0 -243
  47. package/dist/cjs/cli/commands/build.d.ts +0 -11
  48. package/dist/cjs/cli/commands/build.js +0 -446
  49. package/dist/cjs/cli/commands/create.js +0 -125
  50. package/dist/cjs/cli/commands/helpers/copy-template.js +0 -53
  51. package/dist/cjs/cli/commands/helpers/generate-bundle-entrypoint.d.ts +0 -3
  52. package/dist/cjs/cli/commands/helpers/generate-bundle-entrypoint.js +0 -24
  53. package/dist/cjs/cli/commands/helpers/get-extension-dev-deps.js +0 -27
  54. package/dist/cjs/cli/commands/helpers/load-config.d.ts +0 -3
  55. package/dist/cjs/cli/commands/helpers/load-config.js +0 -21
  56. package/dist/cjs/cli/commands/helpers/validate-cli-options.d.ts +0 -3
  57. package/dist/cjs/cli/commands/helpers/validate-cli-options.js +0 -23
  58. package/dist/cjs/cli/commands/link.js +0 -54
  59. package/dist/cjs/cli/index.d.ts +0 -4
  60. package/dist/cjs/cli/index.js +0 -10
  61. package/dist/cjs/cli/run.d.ts +0 -2
  62. package/dist/cjs/cli/run.js +0 -39
  63. package/dist/cjs/cli/types.d.ts +0 -13
  64. package/dist/cjs/cli/types.js +0 -2
  65. package/dist/cjs/cli/utils/detect-json-indent.js +0 -14
  66. package/dist/cjs/cli/utils/get-package-manager-agent.js +0 -15
  67. package/dist/cjs/cli/utils/get-package-manager-agent.test.d.ts +0 -2
  68. package/dist/cjs/cli/utils/get-package-manager-agent.test.js +0 -24
  69. package/dist/cjs/cli/utils/get-package-manager.js +0 -20
  70. package/dist/cjs/cli/utils/get-package-manager.test.d.ts +0 -2
  71. package/dist/cjs/cli/utils/get-package-manager.test.js +0 -42
  72. package/dist/cjs/cli/utils/get-package-version.js +0 -12
  73. package/dist/cjs/cli/utils/get-sdk-version.js +0 -7
  74. package/dist/cjs/cli/utils/get-template-path.js +0 -10
  75. package/dist/cjs/cli/utils/languages.js +0 -30
  76. package/dist/cjs/cli/utils/logger.js +0 -32
  77. package/dist/cjs/cli/utils/try-parse-json.d.ts +0 -3
  78. package/dist/cjs/cli/utils/try-parse-json.js +0 -11
  79. package/dist/cjs/index.js +0 -24
  80. package/dist/esm/cli/commands/add.d.ts +0 -2
  81. package/dist/esm/cli/commands/create.d.ts +0 -6
  82. package/dist/esm/cli/commands/helpers/copy-template.d.ts +0 -4
  83. package/dist/esm/cli/commands/helpers/generate-bundle-entrypoint.d.ts +0 -3
  84. package/dist/esm/cli/commands/helpers/get-extension-dev-deps.d.ts +0 -4
  85. package/dist/esm/cli/commands/helpers/load-config.d.ts +0 -3
  86. package/dist/esm/cli/commands/helpers/validate-cli-options.d.ts +0 -3
  87. package/dist/esm/cli/commands/link.d.ts +0 -2
  88. package/dist/esm/cli/index.d.ts +0 -4
  89. package/dist/esm/cli/index.js +0 -3
  90. package/dist/esm/cli/run.d.ts +0 -2
  91. package/dist/esm/cli/utils/detect-json-indent.d.ts +0 -2
  92. package/dist/esm/cli/utils/get-package-manager-agent.d.ts +0 -5
  93. package/dist/esm/cli/utils/get-package-manager-agent.test.d.ts +0 -2
  94. package/dist/esm/cli/utils/get-package-manager.d.ts +0 -5
  95. package/dist/esm/cli/utils/get-package-manager.test.d.ts +0 -2
  96. package/dist/esm/cli/utils/get-package-version.d.ts +0 -2
  97. package/dist/esm/cli/utils/get-sdk-version.d.ts +0 -2
  98. package/dist/esm/cli/utils/get-sdk-version.js +0 -4
  99. package/dist/esm/cli/utils/get-template-path.d.ts +0 -2
  100. package/dist/esm/cli/utils/languages.d.ts +0 -5
  101. package/dist/esm/cli/utils/logger.d.ts +0 -3
  102. package/dist/esm/cli/utils/try-parse-json.d.ts +0 -3
  103. package/dist/esm/index.d.ts +0 -3
  104. package/license +0 -674
  105. package/readme.md +0 -3
  106. /package/dist/{esm/cli/types.js → cli/run.d.ts} +0 -0
  107. /package/dist/{esm/cli → cli}/utils/get-package-version.js +0 -0
  108. /package/dist/{esm/cli → cli}/utils/get-template-path.js +0 -0
  109. /package/dist/{esm/cli → cli}/utils/logger.js +0 -0
  110. /package/dist/{esm/cli → cli}/utils/try-parse-json.js +0 -0
package/cli.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require('./dist/cjs/cli/run.js');
2
+ import './dist/esm/cli/run.js';
@@ -1,2 +1 @@
1
1
  export default function add(): Promise<void>;
2
- //# sourceMappingURL=add.d.ts.map
@@ -1,21 +1,19 @@
1
- import path from 'path';
1
+ import { EXTENSION_LANGUAGES, EXTENSION_NAME_REGEX, EXTENSION_PKG_KEY, EXTENSION_TYPES, ExtensionManifest, HYBRID_EXTENSION_TYPES, } from '@directus/constants';
2
+ import { isIn, isTypeIn } from '@directus/utils';
3
+ import { pathToRelativeUrl } from '@directus/utils/node';
2
4
  import chalk from 'chalk';
5
+ import execa from 'execa';
3
6
  import fse from 'fs-extra';
4
7
  import inquirer from 'inquirer';
5
- import { log } from '../utils/logger';
6
- import { ExtensionManifest, } from '@directus/shared/types';
7
- import { isIn, isTypeIn } from '@directus/shared/utils';
8
- import { pathToRelativeUrl } from '@directus/shared/utils/node';
9
- import { EXTENSION_LANGUAGES, EXTENSION_NAME_REGEX, EXTENSION_PKG_KEY, EXTENSION_TYPES, HYBRID_EXTENSION_TYPES, } from '@directus/shared/constants';
10
- import { getLanguageFromPath, isLanguage, languageToShort } from '../utils/languages';
11
- import getExtensionDevDeps from './helpers/get-extension-dev-deps';
12
- import execa from 'execa';
13
8
  import ora from 'ora';
14
- import copyTemplate from './helpers/copy-template';
15
- import detectJsonIndent from '../utils/detect-json-indent';
16
- import getPackageManager from '../utils/get-package-manager';
9
+ import path from 'path';
10
+ import detectJsonIndent from '../utils/detect-json-indent.js';
11
+ import getPackageManager from '../utils/get-package-manager.js';
12
+ import { getLanguageFromPath, isLanguage, languageToShort } from '../utils/languages.js';
13
+ import { log } from '../utils/logger.js';
14
+ import copyTemplate from './helpers/copy-template.js';
15
+ import getExtensionDevDeps from './helpers/get-extension-dev-deps.js';
17
16
  export default async function add() {
18
- var _a, _b;
19
17
  const extensionPath = process.cwd();
20
18
  const packagePath = path.resolve('package.json');
21
19
  if (!(await fse.pathExists(packagePath))) {
@@ -63,7 +61,7 @@ export default async function add() {
63
61
  },
64
62
  ]);
65
63
  const spinner = ora(chalk.bold('Modifying Directus extension...')).start();
66
- const source = alternativeSource !== null && alternativeSource !== void 0 ? alternativeSource : 'src';
64
+ const source = alternativeSource ?? 'src';
67
65
  const sourcePath = path.resolve(source, name);
68
66
  await fse.ensureDir(sourcePath);
69
67
  await copyTemplate(type, extensionPath, sourcePath, language);
@@ -90,7 +88,7 @@ export default async function add() {
90
88
  [EXTENSION_PKG_KEY]: newExtensionOptions,
91
89
  devDependencies: await getExtensionDevDeps(newEntries.map((entry) => entry.type), getLanguageFromEntries(newEntries)),
92
90
  };
93
- await fse.writeJSON(packagePath, newExtensionManifest, { spaces: indent !== null && indent !== void 0 ? indent : '\t' });
91
+ await fse.writeJSON(packagePath, newExtensionManifest, { spaces: indent ?? '\t' });
94
92
  const packageManager = getPackageManager();
95
93
  await execa(packageManager, ['install'], { cwd: extensionPath });
96
94
  spinner.succeed(chalk.bold('Done'));
@@ -107,7 +105,7 @@ export default async function add() {
107
105
  log(`Extension has not been modified.`, 'info');
108
106
  process.exit(1);
109
107
  }
110
- const oldName = (_b = (_a = extensionManifest.name.match(EXTENSION_NAME_REGEX)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : extensionManifest.name;
108
+ const oldName = extensionManifest.name.match(EXTENSION_NAME_REGEX)?.[1] ?? extensionManifest.name;
111
109
  const { type, name, language, convertName, extensionName, alternativeSource } = await inquirer.prompt([
112
110
  {
113
111
  type: 'list',
@@ -149,7 +147,7 @@ export default async function add() {
149
147
  },
150
148
  ]);
151
149
  const spinner = ora(chalk.bold('Modifying Directus extension...')).start();
152
- const source = alternativeSource !== null && alternativeSource !== void 0 ? alternativeSource : 'src';
150
+ const source = alternativeSource ?? 'src';
153
151
  const convertSourcePath = path.resolve(source, convertName);
154
152
  const entrySourcePath = path.resolve(source, name);
155
153
  const convertFiles = await fse.readdir(source);
@@ -201,7 +199,7 @@ export default async function add() {
201
199
  [EXTENSION_PKG_KEY]: newExtensionOptions,
202
200
  devDependencies: await getExtensionDevDeps(entries.map((entry) => entry.type), getLanguageFromEntries(entries)),
203
201
  };
204
- await fse.writeJSON(packagePath, newExtensionManifest, { spaces: indent !== null && indent !== void 0 ? indent : '\t' });
202
+ await fse.writeJSON(packagePath, newExtensionManifest, { spaces: indent ?? '\t' });
205
203
  const packageManager = getPackageManager();
206
204
  await execa(packageManager, ['install'], { cwd: extensionPath });
207
205
  spinner.succeed(chalk.bold('Done'));
@@ -8,4 +8,3 @@ type BuildOptions = {
8
8
  };
9
9
  export default function build(options: BuildOptions): Promise<void>;
10
10
  export {};
11
- //# sourceMappingURL=build.d.ts.map
@@ -1,6 +1,5 @@
1
- import { API_SHARED_DEPS, APP_EXTENSION_TYPES, APP_SHARED_DEPS, EXTENSION_PKG_KEY, EXTENSION_TYPES, HYBRID_EXTENSION_TYPES, } from '@directus/shared/constants';
2
- import { ExtensionManifest, ExtensionOptionsBundleEntries, } from '@directus/shared/types';
3
- import { isIn, isTypeIn } from '@directus/shared/utils';
1
+ import { API_SHARED_DEPS, APP_EXTENSION_TYPES, APP_SHARED_DEPS, EXTENSION_PKG_KEY, EXTENSION_TYPES, ExtensionManifest, ExtensionOptionsBundleEntries, HYBRID_EXTENSION_TYPES, } from '@directus/constants';
2
+ import { isIn, isTypeIn } from '@directus/utils';
4
3
  import commonjs from '@rollup/plugin-commonjs';
5
4
  import json from '@rollup/plugin-json';
6
5
  import { nodeResolve } from '@rollup/plugin-node-resolve';
@@ -15,17 +14,16 @@ import { rollup, watch as rollupWatch, } from 'rollup';
15
14
  import esbuild from 'rollup-plugin-esbuild';
16
15
  import styles from 'rollup-plugin-styles';
17
16
  import vue from 'rollup-plugin-vue';
18
- import { getLanguageFromPath, isLanguage } from '../utils/languages';
19
- import { clear, log } from '../utils/logger';
20
- import tryParseJson from '../utils/try-parse-json';
21
- import generateBundleEntrypoint from './helpers/generate-bundle-entrypoint';
22
- import loadConfig from './helpers/load-config';
23
- import { validateSplitEntrypointOption } from './helpers/validate-cli-options';
17
+ import { getLanguageFromPath, isLanguage } from '../utils/languages.js';
18
+ import { clear, log } from '../utils/logger.js';
19
+ import tryParseJson from '../utils/try-parse-json.js';
20
+ import generateBundleEntrypoint from './helpers/generate-bundle-entrypoint.js';
21
+ import loadConfig from './helpers/load-config.js';
22
+ import { validateSplitEntrypointOption } from './helpers/validate-cli-options.js';
24
23
  export default async function build(options) {
25
- var _a, _b, _c;
26
- const watch = (_a = options.watch) !== null && _a !== void 0 ? _a : false;
27
- const sourcemap = (_b = options.sourcemap) !== null && _b !== void 0 ? _b : false;
28
- const minify = (_c = options.minify) !== null && _c !== void 0 ? _c : false;
24
+ const watch = options.watch ?? false;
25
+ const sourcemap = options.sourcemap ?? false;
26
+ const minify = options.minify ?? false;
29
27
  if (!options.type && !options.input && !options.output) {
30
28
  const packagePath = path.resolve('package.json');
31
29
  if (!(await fse.pathExists(packagePath))) {
@@ -147,7 +145,6 @@ export default async function build(options) {
147
145
  }
148
146
  }
149
147
  async function buildAppOrApiExtension({ type, input, output, watch, sourcemap, minify, }) {
150
- var _a;
151
148
  if (!(await fse.pathExists(input)) || !(await fse.stat(input)).isFile()) {
152
149
  log(`Entrypoint ${chalk.bold(input)} does not exist.`, 'error');
153
150
  process.exit(1);
@@ -162,7 +159,7 @@ async function buildAppOrApiExtension({ type, input, output, watch, sourcemap, m
162
159
  process.exit(1);
163
160
  }
164
161
  const config = await loadConfig();
165
- const plugins = (_a = config.plugins) !== null && _a !== void 0 ? _a : [];
162
+ const plugins = config.plugins ?? [];
166
163
  const mode = isIn(type, APP_EXTENSION_TYPES) ? 'browser' : 'node';
167
164
  const rollupOptions = getRollupOptions({ mode, input, language, sourcemap, minify, plugins });
168
165
  const rollupOutputOptions = getRollupOutputOptions({ mode, output, sourcemap });
@@ -174,7 +171,6 @@ async function buildAppOrApiExtension({ type, input, output, watch, sourcemap, m
174
171
  }
175
172
  }
176
173
  async function buildHybridExtension({ inputApp, inputApi, outputApp, outputApi, watch, sourcemap, minify, }) {
177
- var _a;
178
174
  if (!(await fse.pathExists(inputApp)) || !(await fse.stat(inputApp)).isFile()) {
179
175
  log(`App entrypoint ${chalk.bold(inputApp)} does not exist.`, 'error');
180
176
  process.exit(1);
@@ -202,7 +198,7 @@ async function buildHybridExtension({ inputApp, inputApi, outputApp, outputApi,
202
198
  process.exit(1);
203
199
  }
204
200
  const config = await loadConfig();
205
- const plugins = (_a = config.plugins) !== null && _a !== void 0 ? _a : [];
201
+ const plugins = config.plugins ?? [];
206
202
  const rollupOptionsApp = getRollupOptions({
207
203
  mode: 'browser',
208
204
  input: inputApp,
@@ -233,7 +229,6 @@ async function buildHybridExtension({ inputApp, inputApi, outputApp, outputApi,
233
229
  }
234
230
  }
235
231
  async function buildBundleExtension({ entries, outputApp, outputApi, watch, sourcemap, minify, }) {
236
- var _a;
237
232
  if (outputApp.length === 0) {
238
233
  log(`App output file can not be empty.`, 'error');
239
234
  process.exit(1);
@@ -289,7 +284,7 @@ async function buildBundleExtension({ entries, outputApp, outputApi, watch, sour
289
284
  }
290
285
  }
291
286
  const config = await loadConfig();
292
- const plugins = (_a = config.plugins) !== null && _a !== void 0 ? _a : [];
287
+ const plugins = config.plugins ?? [];
293
288
  const entrypointApp = generateBundleEntrypoint('app', entries);
294
289
  const entrypointApi = generateBundleEntrypoint('api', entries);
295
290
  const rollupOptionsApp = getRollupOptions({
@@ -390,21 +385,21 @@ function getRollupOptions({ mode, input, language, sourcemap, minify, plugins, }
390
385
  input: typeof input !== 'string' ? 'entry' : input,
391
386
  external: mode === 'browser' ? APP_SHARED_DEPS : API_SHARED_DEPS,
392
387
  plugins: [
393
- typeof input !== 'string' ? virtual(input) : null,
394
- mode === 'browser' ? vue({ preprocessStyles: true }) : null,
395
- languages.includes('typescript') ? esbuild({ include: /\.tsx?$/, sourceMap: sourcemap }) : null,
396
- mode === 'browser' ? styles() : null,
388
+ typeof input !== 'string' ? virtual.default(input) : null,
389
+ mode === 'browser' ? vue.default({ preprocessStyles: true }) : null,
390
+ languages.includes('typescript') ? esbuild.default({ include: /\.tsx?$/, sourceMap: sourcemap }) : null,
391
+ mode === 'browser' ? styles.default() : null,
397
392
  ...plugins,
398
393
  nodeResolve({ browser: mode === 'browser' }),
399
- commonjs({ esmExternals: mode === 'browser', sourceMap: sourcemap }),
400
- json(),
401
- replace({
394
+ commonjs.default({ esmExternals: mode === 'browser', sourceMap: sourcemap }),
395
+ json.default(),
396
+ replace.default({
402
397
  values: {
403
398
  'process.env.NODE_ENV': JSON.stringify('production'),
404
399
  },
405
400
  preventAssignment: true,
406
401
  }),
407
- minify ? terser() : null,
402
+ minify ? terser.default() : null,
408
403
  ],
409
404
  };
410
405
  }
@@ -418,14 +413,13 @@ function getRollupOutputOptions({ mode, output, sourcemap, }) {
418
413
  };
419
414
  }
420
415
  function formatRollupError(error) {
421
- var _a;
422
416
  let message = '';
423
417
  message += `${chalk.bold.red(`[${error.name}]`)} ${error.message}${error.plugin ? ` (plugin ${error.plugin})` : ''}\n`;
424
418
  if (error.url) {
425
419
  message += '\n' + chalk.green(error.url);
426
420
  }
427
421
  if (error.loc) {
428
- message += '\n' + chalk.green(`${(_a = error.loc.file) !== null && _a !== void 0 ? _a : error.id}:${error.loc.line}:${error.loc.column}`);
422
+ message += '\n' + chalk.green(`${error.loc.file ?? error.id}:${error.loc.line}:${error.loc.column}`);
429
423
  }
430
424
  else if (error.id) {
431
425
  message += '\n' + chalk.green(error.id);
@@ -3,4 +3,3 @@ type CreateOptions = {
3
3
  };
4
4
  export default function create(type: string, name: string, options: CreateOptions): Promise<void>;
5
5
  export {};
6
- //# sourceMappingURL=create.d.ts.map
@@ -1,18 +1,17 @@
1
- import path from 'path';
1
+ import { BUNDLE_EXTENSION_TYPES, EXTENSION_LANGUAGES, EXTENSION_NAME_REGEX, EXTENSION_PKG_KEY, EXTENSION_TYPES, HYBRID_EXTENSION_TYPES, } from '@directus/constants';
2
+ import { isIn } from '@directus/utils';
2
3
  import chalk from 'chalk';
3
- import fse from 'fs-extra';
4
4
  import execa from 'execa';
5
+ import fse from 'fs-extra';
5
6
  import ora from 'ora';
6
- import { EXTENSION_PKG_KEY, EXTENSION_LANGUAGES, HYBRID_EXTENSION_TYPES, EXTENSION_NAME_REGEX, EXTENSION_TYPES, BUNDLE_EXTENSION_TYPES, } from '@directus/shared/constants';
7
- import { isIn } from '@directus/shared/utils';
8
- import { log } from '../utils/logger';
9
- import { isLanguage, languageToShort } from '../utils/languages';
10
- import getSdkVersion from '../utils/get-sdk-version';
11
- import getExtensionDevDeps from './helpers/get-extension-dev-deps';
12
- import copyTemplate from './helpers/copy-template';
13
- import getPackageManager from '../utils/get-package-manager';
7
+ import path from 'path';
8
+ import getPackageManager from '../utils/get-package-manager.js';
9
+ import getSdkVersion from '../utils/get-sdk-version.js';
10
+ import { isLanguage, languageToShort } from '../utils/languages.js';
11
+ import { log } from '../utils/logger.js';
12
+ import copyTemplate from './helpers/copy-template.js';
13
+ import getExtensionDevDeps from './helpers/get-extension-dev-deps.js';
14
14
  export default async function create(type, name, options) {
15
- var _a;
16
15
  const targetDir = name.substring(name.lastIndexOf('/') + 1);
17
16
  const targetPath = path.resolve(targetDir);
18
17
  if (!isIn(type, EXTENSION_TYPES)) {
@@ -39,7 +38,7 @@ export default async function create(type, name, options) {
39
38
  await createPackageExtension({ type, name, targetDir, targetPath });
40
39
  }
41
40
  else {
42
- const language = (_a = options.language) !== null && _a !== void 0 ? _a : 'javascript';
41
+ const language = options.language ?? 'javascript';
43
42
  await createLocalExtension({ type, name, targetDir, targetPath, language });
44
43
  }
45
44
  }
@@ -101,7 +100,7 @@ function getPackageManifest(name, options, deps) {
101
100
  devDependencies: deps,
102
101
  };
103
102
  if (options.type === 'bundle') {
104
- packageManifest.scripts['add'] = 'directus-extension add';
103
+ packageManifest['scripts']['add'] = 'directus-extension add';
105
104
  }
106
105
  return packageManifest;
107
106
  }
@@ -1,4 +1,3 @@
1
- import { ExtensionType } from '@directus/shared/types';
2
- import { Language } from '../../types';
1
+ import type { ExtensionType } from '@directus/types';
2
+ import type { Language } from '../../types.js';
3
3
  export default function copyTemplate(type: ExtensionType, extensionPath: string, sourcePath?: string, language?: Language): Promise<void>;
4
- //# sourceMappingURL=copy-template.d.ts.map
@@ -1,6 +1,6 @@
1
- import path from 'path';
2
1
  import fse from 'fs-extra';
3
- import getTemplatePath from '../../utils/get-template-path';
2
+ import path from 'path';
3
+ import getTemplatePath from '../../utils/get-template-path.js';
4
4
  async function copyTemplateFile(templateFile, extensionPath, sourcePath) {
5
5
  if (sourcePath !== undefined) {
6
6
  const oldName = path.basename(templateFile.path);
@@ -0,0 +1,2 @@
1
+ import type { ExtensionOptionsBundleEntry } from '@directus/types';
2
+ export default function generateBundleEntrypoint(mode: 'app' | 'api', entries: ExtensionOptionsBundleEntry[]): string;
@@ -1,7 +1,7 @@
1
+ import { API_EXTENSION_TYPES, APP_EXTENSION_TYPES, HYBRID_EXTENSION_TYPES } from '@directus/constants';
2
+ import { isIn, isTypeIn, pluralize } from '@directus/utils';
3
+ import { pathToRelativeUrl } from '@directus/utils/node';
1
4
  import path from 'path';
2
- import { API_EXTENSION_TYPES, APP_EXTENSION_TYPES, HYBRID_EXTENSION_TYPES } from '@directus/shared/constants';
3
- import { isIn, isTypeIn, pluralize } from '@directus/shared/utils';
4
- import { pathToRelativeUrl } from '@directus/shared/utils/node';
5
5
  export default function generateBundleEntrypoint(mode, entries) {
6
6
  const types = [...(mode === 'app' ? APP_EXTENSION_TYPES : API_EXTENSION_TYPES), ...HYBRID_EXTENSION_TYPES];
7
7
  const entriesForTypes = entries.filter((entry) => isIn(entry.type, types));
@@ -1,4 +1,3 @@
1
- import { ExtensionType } from '@directus/shared/types';
2
- import { Language } from '../../types';
1
+ import type { ExtensionType } from '@directus/types';
2
+ import type { Language } from '../../types.js';
3
3
  export default function getExtensionDevDeps(type: ExtensionType | ExtensionType[], language?: Language | Language[]): Promise<Record<string, string>>;
4
- //# sourceMappingURL=get-extension-dev-deps.d.ts.map
@@ -1,7 +1,7 @@
1
- import { APP_EXTENSION_TYPES, API_EXTENSION_TYPES, HYBRID_EXTENSION_TYPES } from '@directus/shared/constants';
2
- import { isIn } from '@directus/shared/utils';
3
- import getPackageVersion from '../../utils/get-package-version';
4
- import getSdkVersion from '../../utils/get-sdk-version';
1
+ import { API_EXTENSION_TYPES, APP_EXTENSION_TYPES, HYBRID_EXTENSION_TYPES } from '@directus/constants';
2
+ import { isIn } from '@directus/utils';
3
+ import getPackageVersion from '../../utils/get-package-version.js';
4
+ import getSdkVersion from '../../utils/get-sdk-version.js';
5
5
  export default async function getExtensionDevDeps(type, language = []) {
6
6
  const types = Array.isArray(type) ? type : [type];
7
7
  const languages = Array.isArray(language) ? language : [language];
@@ -0,0 +1,2 @@
1
+ import type { Config } from '../../types.js';
2
+ export default function loadConfig(): Promise<Config>;
@@ -1,6 +1,6 @@
1
- import path from 'path';
1
+ import { pathToRelativeUrl } from '@directus/utils/node';
2
2
  import fse from 'fs-extra';
3
- import { pathToRelativeUrl } from '@directus/shared/utils/node';
3
+ import path from 'path';
4
4
  const CONFIG_FILE_NAMES = ['extension.config.js', 'extension.config.mjs', 'extension.config.cjs'];
5
5
  // This is needed to work around Typescript always transpiling import() to require() for CommonJS targets.
6
6
  const _import = new Function('url', 'return import(url)');
@@ -0,0 +1,2 @@
1
+ import type { JsonValue, SplitEntrypoint } from '@directus/types';
2
+ export declare function validateSplitEntrypointOption(option: JsonValue | undefined): option is SplitEntrypoint;
@@ -12,7 +12,7 @@ export function validateSplitEntrypointOption(option) {
12
12
  if (!validateNonPrimitive(option) || Array.isArray(option)) {
13
13
  return false;
14
14
  }
15
- if (!option.app || !option.api) {
15
+ if (!option['app'] || !option['api']) {
16
16
  return false;
17
17
  }
18
18
  return true;
@@ -1,2 +1 @@
1
1
  export default function link(extensionsPath: string): Promise<void>;
2
- //# sourceMappingURL=link.d.ts.map
@@ -1,9 +1,8 @@
1
- import path from 'path';
1
+ import { ExtensionManifest } from '@directus/constants';
2
2
  import fs from 'fs-extra';
3
- import { log } from '../utils/logger';
4
- import { ExtensionManifest } from '@directus/shared/types';
3
+ import path from 'path';
4
+ import { log } from '../utils/logger.js';
5
5
  export default async function link(extensionsPath) {
6
- var _a;
7
6
  const extensionPath = process.cwd();
8
7
  const absoluteExtensionsPath = path.resolve(extensionsPath);
9
8
  if (!fs.existsSync(absoluteExtensionsPath)) {
@@ -29,7 +28,7 @@ export default async function link(extensionsPath) {
29
28
  log(`Extension name not found in package.json`, 'error');
30
29
  return;
31
30
  }
32
- const type = (_a = extensionManifest['directus:extension']) === null || _a === void 0 ? void 0 : _a.type;
31
+ const type = extensionManifest['directus:extension']?.type;
33
32
  if (!type) {
34
33
  log(`Extension type not found in package.json`, 'error');
35
34
  return;
@@ -0,0 +1,3 @@
1
+ import build from './commands/build.js';
2
+ import create from './commands/create.js';
3
+ export { create, build };
@@ -0,0 +1,3 @@
1
+ import build from './commands/build.js';
2
+ import create from './commands/create.js';
3
+ export { create, build };
@@ -1,8 +1,8 @@
1
1
  import { Command } from 'commander';
2
- import create from './commands/create';
3
- import add from './commands/add';
4
- import build from './commands/build';
5
- import link from './commands/link';
2
+ import add from './commands/add.js';
3
+ import build from './commands/build.js';
4
+ import create from './commands/create.js';
5
+ import link from './commands/link.js';
6
6
  const pkg = require('../../../package.json');
7
7
  const program = new Command();
8
8
  program.name('directus-extension').usage('[command] [options]');
@@ -1,5 +1,5 @@
1
- import { EXTENSION_LANGUAGES } from '@directus/shared/constants';
2
- import { Plugin, RollupOptions, OutputOptions as RollupOutputOptions } from 'rollup';
1
+ import type { EXTENSION_LANGUAGES } from '@directus/constants';
2
+ import type { Plugin, RollupOptions, OutputOptions as RollupOutputOptions } from 'rollup';
3
3
  export type Language = (typeof EXTENSION_LANGUAGES)[number];
4
4
  export type LanguageShort = 'js' | 'ts';
5
5
  export type Config = {
@@ -10,4 +10,3 @@ export type RollupConfig = {
10
10
  rollupOutputOptions: RollupOutputOptions;
11
11
  };
12
12
  export type RollupMode = 'browser' | 'node';
13
- //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1 @@
1
1
  export default function detectJsonIndent(json: string): string | null;
2
- //# sourceMappingURL=detect-json-indent.d.ts.map
@@ -1,10 +1,9 @@
1
1
  export default function detectJsonIndent(json) {
2
- var _a;
3
2
  const lines = json.split(/\r?\n/);
4
3
  const braceLine = lines.findIndex((line) => /^(?:\{|\[)/.test(line));
5
4
  if (braceLine === -1 || braceLine + 1 > lines.length - 1)
6
5
  return null;
7
- const indent = (_a = lines[braceLine + 1].match(/[ \t]+/)) === null || _a === void 0 ? void 0 : _a[0];
6
+ const indent = lines[braceLine + 1].match(/[ \t]+/)?.[0];
8
7
  if (indent === undefined)
9
8
  return null;
10
9
  return indent;
@@ -2,4 +2,3 @@
2
2
  * Extract the npm user agent from the npm_config_user_agent environment variable string
3
3
  */
4
4
  export default function getPackageManagerAgent(): Record<string, string> | null;
5
- //# sourceMappingURL=get-package-manager-agent.d.ts.map
@@ -2,7 +2,7 @@
2
2
  * Extract the npm user agent from the npm_config_user_agent environment variable string
3
3
  */
4
4
  export default function getPackageManagerAgent() {
5
- const userAgent = process.env.npm_config_user_agent;
5
+ const userAgent = process.env['npm_config_user_agent'];
6
6
  if (!userAgent)
7
7
  return null;
8
8
  const values = userAgent.split(' ');
@@ -0,0 +1 @@
1
+ export {};
@@ -1,15 +1,15 @@
1
1
  import { afterEach, expect, test } from 'vitest';
2
- import getPackageManagerAgent from './get-package-manager-agent';
2
+ import getPackageManagerAgent from './get-package-manager-agent.js';
3
3
  const envCopy = { ...process.env };
4
4
  afterEach(() => {
5
5
  process.env = envCopy;
6
6
  });
7
7
  test('Returns null if user agent cannot be extracted from env', () => {
8
- delete process.env.npm_config_user_agent;
8
+ delete process.env['npm_config_user_agent'];
9
9
  expect(getPackageManagerAgent()).toBe(null);
10
10
  });
11
11
  test('Returns information object from parsed user agent', () => {
12
- process.env.npm_config_user_agent = 'pnpm/7.16.0 npm/? node/v18.12.1 darwin arm64';
12
+ process.env['npm_config_user_agent'] = 'pnpm/7.16.0 npm/? node/v18.12.1 darwin arm64';
13
13
  expect(getPackageManagerAgent()).toStrictEqual({
14
14
  node: 'v18.12.1',
15
15
  npm: '?',
@@ -2,4 +2,3 @@
2
2
  * Determine whether to use pnpm, yarn, or npm based on the parsed package manager agent info
3
3
  */
4
4
  export default function getPackageManager(): string;
5
- //# sourceMappingURL=get-package-manager.d.ts.map
@@ -1,13 +1,13 @@
1
- import getPackageManagerAgent from './get-package-manager-agent';
1
+ import getPackageManagerAgent from './get-package-manager-agent.js';
2
2
  /**
3
3
  * Determine whether to use pnpm, yarn, or npm based on the parsed package manager agent info
4
4
  */
5
5
  export default function getPackageManager() {
6
6
  const agent = getPackageManagerAgent();
7
7
  if (agent !== null) {
8
- if ('pnpm' in agent && agent.pnpm !== '?')
8
+ if ('pnpm' in agent && agent['pnpm'] !== '?')
9
9
  return 'pnpm';
10
- if ('yarn' in agent && agent.yarn !== '?')
10
+ if ('yarn' in agent && agent['yarn'] !== '?')
11
11
  return 'yarn';
12
12
  }
13
13
  return 'npm';
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,6 @@
1
- import { vi, afterEach, expect, test } from 'vitest';
2
- import getPackageManagerAgent from './get-package-manager-agent';
3
- import getPackageManager from './get-package-manager';
1
+ import { afterEach, expect, test, vi } from 'vitest';
2
+ import getPackageManagerAgent from './get-package-manager-agent.js';
3
+ import getPackageManager from './get-package-manager.js';
4
4
  vi.mock('./get-package-manager-agent');
5
5
  afterEach(() => {
6
6
  vi.clearAllMocks();
@@ -1,2 +1 @@
1
1
  export default function getPackageVersion(name: string, tag?: string): Promise<string>;
2
- //# sourceMappingURL=get-package-version.d.ts.map
@@ -1,2 +1 @@
1
1
  export default function getSdkVersion(): string;
2
- //# sourceMappingURL=get-sdk-version.d.ts.map
@@ -0,0 +1,8 @@
1
+ import { dirname } from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { resolve } from 'node:path';
4
+ import { readFileSync } from 'node:fs';
5
+ const pkg = JSON.parse(readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), '../../../../package.json'), 'utf8'));
6
+ export default function getSdkVersion() {
7
+ return pkg.version;
8
+ }
@@ -1,2 +1 @@
1
1
  export default function getTemplatePath(): string;
2
- //# sourceMappingURL=get-template-path.d.ts.map
@@ -1,5 +1,4 @@
1
- import { Language, LanguageShort } from '../types';
1
+ import type { Language, LanguageShort } from '../types.js';
2
2
  export declare function isLanguage(language: string): language is Language;
3
3
  export declare function languageToShort(language: Language): LanguageShort;
4
4
  export declare function getLanguageFromPath(path: string): string;
5
- //# sourceMappingURL=languages.d.ts.map
@@ -1,4 +1,4 @@
1
- import { EXTENSION_LANGUAGES } from '@directus/shared/constants';
1
+ import { EXTENSION_LANGUAGES } from '@directus/constants';
2
2
  export function isLanguage(language) {
3
3
  return EXTENSION_LANGUAGES.includes(language);
4
4
  }
@@ -1,3 +1,2 @@
1
1
  export declare function log(message: string, type?: 'info' | 'warn' | 'error'): void;
2
2
  export declare function clear(): void;
3
- //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1,2 @@
1
+ import type { JsonValue } from '@directus/types';
2
+ export default function tryParseJson(str: string): JsonValue | undefined;
@@ -1,3 +1,2 @@
1
- export { defineInterface, defineDisplay, defineLayout, defineModule, definePanel, defineHook, defineEndpoint, defineOperationApp, defineOperationApi, getFieldsFromTemplate, getRelationType, } from '@directus/shared/utils';
2
- export { useStores, useApi, useExtensions, useSync, useCollection, useItems, useLayout, useFilterFields, } from '@directus/shared/composables';
3
- //# sourceMappingURL=index.d.ts.map
1
+ export { defineInterface, defineDisplay, defineLayout, defineModule, definePanel, defineHook, defineEndpoint, defineOperationApp, defineOperationApi, getFieldsFromTemplate, getRelationType, } from '@directus/utils';
2
+ export { useStores, useApi, useExtensions, useSync, useCollection, useItems, useLayout, useFilterFields, } from '@directus/composables';
@@ -1,2 +1,2 @@
1
- export { defineInterface, defineDisplay, defineLayout, defineModule, definePanel, defineHook, defineEndpoint, defineOperationApp, defineOperationApi, getFieldsFromTemplate, getRelationType, } from '@directus/shared/utils';
2
- export { useStores, useApi, useExtensions, useSync, useCollection, useItems, useLayout, useFilterFields, } from '@directus/shared/composables';
1
+ export { defineInterface, defineDisplay, defineLayout, defineModule, definePanel, defineHook, defineEndpoint, defineOperationApp, defineOperationApi, getFieldsFromTemplate, getRelationType, } from '@directus/utils';
2
+ export { useStores, useApi, useExtensions, useSync, useCollection, useItems, useLayout, useFilterFields, } from '@directus/composables';