@strapi/strapi 5.30.0 → 5.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json.js +1 -1
- package/dist/package.json.mjs +1 -1
- package/dist/src/cli/commands/configuration/restore.js.map +1 -1
- package/dist/src/cli/commands/configuration/restore.mjs.map +1 -1
- package/dist/src/cli/commands/export/action.js.map +1 -1
- package/dist/src/cli/commands/export/action.mjs.map +1 -1
- package/dist/src/cli/commands/import/action.js.map +1 -1
- package/dist/src/cli/commands/import/action.mjs.map +1 -1
- package/dist/src/cli/commands/openapi/generate.js.map +1 -1
- package/dist/src/cli/commands/openapi/generate.mjs.map +1 -1
- package/dist/src/cli/commands/report.js.map +1 -1
- package/dist/src/cli/commands/report.mjs.map +1 -1
- package/dist/src/cli/commands/start.js.map +1 -1
- package/dist/src/cli/commands/start.mjs.map +1 -1
- package/dist/src/cli/commands/telemetry/disable.js.map +1 -1
- package/dist/src/cli/commands/telemetry/disable.mjs.map +1 -1
- package/dist/src/cli/commands/telemetry/enable.js.map +1 -1
- package/dist/src/cli/commands/telemetry/enable.mjs.map +1 -1
- package/dist/src/cli/commands/transfer/command.js.map +1 -1
- package/dist/src/cli/commands/transfer/command.mjs.map +1 -1
- package/dist/src/cli/commands/version.js.map +1 -1
- package/dist/src/cli/commands/version.mjs.map +1 -1
- package/dist/src/cli/utils/commander.js.map +1 -1
- package/dist/src/cli/utils/commander.mjs.map +1 -1
- package/dist/src/cli/utils/data-transfer.js.map +1 -1
- package/dist/src/cli/utils/data-transfer.mjs.map +1 -1
- package/dist/src/cli/utils/helpers.js.map +1 -1
- package/dist/src/cli/utils/helpers.mjs.map +1 -1
- package/dist/src/cli/utils/logger.js.map +1 -1
- package/dist/src/cli/utils/logger.mjs.map +1 -1
- package/dist/src/cli/utils/telemetry.js.map +1 -1
- package/dist/src/cli/utils/telemetry.mjs.map +1 -1
- package/dist/src/node/core/dependencies.js.map +1 -1
- package/dist/src/node/core/dependencies.mjs.map +1 -1
- package/dist/src/node/core/errors.js.map +1 -1
- package/dist/src/node/core/errors.mjs.map +1 -1
- package/dist/src/node/core/plugins.js.map +1 -1
- package/dist/src/node/core/plugins.mjs.map +1 -1
- package/dist/src/node/core/timer.js.map +1 -1
- package/dist/src/node/core/timer.mjs.map +1 -1
- package/dist/src/node/create-build-context.js.map +1 -1
- package/dist/src/node/create-build-context.mjs.map +1 -1
- package/dist/src/node/develop.js.map +1 -1
- package/dist/src/node/develop.mjs.map +1 -1
- package/dist/src/node/staticFiles.js.map +1 -1
- package/dist/src/node/staticFiles.mjs.map +1 -1
- package/dist/src/node/vite/watch.js.map +1 -1
- package/dist/src/node/vite/watch.mjs.map +1 -1
- package/dist/src/node/webpack/config.js.map +1 -1
- package/dist/src/node/webpack/config.mjs.map +1 -1
- package/dist/src/node/webpack/watch.js.map +1 -1
- package/dist/src/node/webpack/watch.mjs.map +1 -1
- package/package.json +22 -22
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.js","sources":["../../../../src/node/core/plugins.ts"],"sourcesContent":["import os from 'node:os';\nimport path from 'node:path';\nimport fs from 'node:fs';\nimport camelCase from 'lodash/camelCase';\nimport { env } from '@strapi/utils';\nimport { getModule, PackageJson } from './dependencies';\nimport { convertModulePathToSystemPath, convertSystemPathToModulePath, loadFile } from './files';\nimport type { BaseContext } from '../types';\nimport { isError } from './errors';\n\ninterface LocalPluginMeta {\n name: string;\n /**\n * camelCased version of the plugin name\n */\n importName: string;\n /**\n * The path to the plugin, relative to the app's root directory\n * in system format\n */\n path: string;\n /**\n * The path to the plugin, relative to the runtime directory\n * in module format (i.e. with forward slashes) because thats\n * where it should be used as an import\n */\n modulePath: string;\n type: 'local';\n}\n\ninterface ModulePluginMeta {\n name: string;\n /**\n * camelCased version of the plugin name\n */\n importName: string;\n /**\n * Modules don't have a path because we never resolve them to their node_modules\n * because we simply do not require it.\n */\n path?: never;\n /**\n * The path to the plugin, relative to the app's root directory\n * in module format (i.e. with forward slashes)\n */\n modulePath: string;\n type: 'module';\n}\n\ntype PluginMeta = LocalPluginMeta | ModulePluginMeta;\n\ninterface StrapiPlugin extends PackageJson {\n strapi: {\n description?: string;\n displayName?: string;\n kind: 'plugin';\n name?: string;\n required?: boolean;\n };\n}\n\nconst validatePackageHasStrapi = (\n pkg: PackageJson\n): pkg is PackageJson & { strapi: Record<string, unknown> } =>\n 'strapi' in pkg &&\n typeof pkg.strapi === 'object' &&\n !Array.isArray(pkg.strapi) &&\n pkg.strapi !== null;\n\nconst validatePackageIsPlugin = (pkg: PackageJson): pkg is StrapiPlugin =>\n validatePackageHasStrapi(pkg) && pkg.strapi.kind === 'plugin';\n\nconst getEnabledPlugins = async ({\n cwd,\n logger,\n runtimeDir,\n strapi,\n}: Pick<BaseContext, 'cwd' | 'logger' | 'strapi' | 'runtimeDir'>): Promise<\n Record<string, PluginMeta>\n> => {\n const plugins: Record<string, PluginMeta> = {};\n\n /**\n * This is the list of dependencies that are installed in the user's project.\n * It will include libraries like \"react\", so we need to collect the ones that\n * are plugins.\n */\n const deps = strapi.config.get('info.dependencies', {});\n\n logger.debug(\"Dependencies from user's project\", os.EOL, deps);\n\n for (const dep of Object.keys(deps)) {\n const pkg = await getModule(dep, cwd);\n\n if (pkg && validatePackageIsPlugin(pkg)) {\n const name = pkg.strapi.name || pkg.name;\n\n if (!name) {\n /**\n * Unlikely to happen, but you never know.\n */\n throw Error(\n \"You're trying to import a plugin that doesn't have a name – check the package.json of that plugin!\"\n );\n }\n\n plugins[name] = {\n name,\n importName: camelCase(name),\n type: 'module',\n modulePath: dep,\n };\n }\n }\n\n const userPluginsFile = await loadUserPluginsFile(strapi.dirs.app.config);\n\n logger.debug(\"User's plugins file\", os.EOL, userPluginsFile);\n\n for (const [userPluginName, userPluginConfig] of Object.entries(userPluginsFile)) {\n if (userPluginConfig.enabled && userPluginConfig.resolve) {\n const sysPath = convertModulePathToSystemPath(userPluginConfig.resolve);\n plugins[userPluginName] = {\n name: userPluginName,\n importName: camelCase(userPluginName),\n type: 'local',\n /**\n * User plugin paths are resolved from the entry point\n * of the app, because that's how you import them.\n */\n modulePath: convertSystemPathToModulePath(path.relative(runtimeDir, sysPath)),\n path: sysPath,\n };\n }\n }\n\n return plugins;\n};\n\nconst PLUGIN_CONFIGS = ['plugins.js', 'plugins.mjs', 'plugins.ts'];\n\ntype UserPluginConfigFile = Record<string, { enabled: boolean; resolve: string }>;\n\nconst loadUserPluginsFile = async (root: string): Promise<UserPluginConfigFile> => {\n for (const file of PLUGIN_CONFIGS) {\n const filePath = path.join(root, file);\n const configFile = await loadFile(filePath);\n\n if (configFile) {\n /**\n * Configs can be a function or they can be just an object!\n */\n return typeof configFile === 'function' ? configFile({ env }) : configFile;\n }\n }\n\n return {};\n};\n\nconst getMapOfPluginsWithAdmin = (plugins: Record<string, PluginMeta>) => {\n /**\n * This variable stores the import paths for plugins.\n * The keys are the module paths of the plugins, and the values are the paths\n * to the admin part of the plugins, which is either loaded from the\n * package.json exports or from the legacy strapi-admin.js file.\n */\n const pluginImportPaths: Record<string, string> = {};\n\n return Object.values(plugins)\n .filter((plugin) => {\n if (!plugin) {\n return false;\n }\n\n /**\n * There are two ways a plugin should be imported, either it's local to the strapi app,\n * or it's an actual npm module that's installed and resolved via node_modules.\n *\n * We first check if the plugin is local to the strapi app, using a regular `fs.existsSync` because\n * the pathToPlugin will be relative i.e. `/Users/my-name/strapi-app/src/plugins/my-plugin`.\n *\n * If the file doesn't exist well then it's probably a node_module, so instead we use `require.resolve`\n * which will resolve the path to the module in node_modules. If it fails with the specific code `MODULE_NOT_FOUND`\n * then it doesn't have an admin part to the package.\n */\n try {\n const localPluginPath = plugin.path;\n if (localPluginPath) {\n // Here we are loading a locally installed plugin\n const packageJsonPath = path.join(localPluginPath, 'package.json');\n\n if (fs.existsSync(packageJsonPath)) {\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));\n const localAdminPath = packageJson?.exports?.['./strapi-admin']?.import;\n\n if (localAdminPath) {\n pluginImportPaths[plugin.modulePath] = localAdminPath;\n return true;\n }\n }\n\n // Check if legacy admin file exists in local plugin\n if (fs.existsSync(path.join(localPluginPath, 'strapi-admin.js'))) {\n pluginImportPaths[plugin.modulePath] = 'strapi-admin';\n return true;\n }\n }\n\n // This plugin is a module, so we need to check if it has a strapi-admin export\n if (require.resolve(`${plugin.modulePath}/strapi-admin`)) {\n pluginImportPaths[plugin.modulePath] = 'strapi-admin';\n return true;\n }\n\n return false;\n } catch (err) {\n if (\n isError(err) &&\n 'code' in err &&\n (err.code === 'MODULE_NOT_FOUND' || err.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED')\n ) {\n /**\n * the plugin does not contain FE code, so we\n * don't want to import it anyway\n */\n return false;\n }\n\n throw err;\n }\n })\n .map((plugin) => ({\n ...plugin,\n modulePath: `${plugin.modulePath}/${pluginImportPaths[plugin.modulePath]}`,\n }));\n};\n\nexport { getEnabledPlugins, getMapOfPluginsWithAdmin };\nexport type { PluginMeta, LocalPluginMeta, ModulePluginMeta };\n"],"names":["validatePackageHasStrapi","pkg","strapi","Array","isArray","validatePackageIsPlugin","kind","getEnabledPlugins","cwd","logger","runtimeDir","plugins","deps","config","get","debug","os","EOL","dep","Object","keys","getModule","name","Error","importName","camelCase","type","modulePath","userPluginsFile","loadUserPluginsFile","dirs","app","userPluginName","userPluginConfig","entries","enabled","resolve","sysPath","convertModulePathToSystemPath","convertSystemPathToModulePath","path","relative","PLUGIN_CONFIGS","root","file","filePath","join","configFile","loadFile","env","getMapOfPluginsWithAdmin","pluginImportPaths","values","filter","plugin","localPluginPath","packageJsonPath","fs","existsSync","packageJson","JSON","parse","readFileSync","localAdminPath","exports","import","require","err","isError","code","map"],"mappings":";;;;;;;;;;;AA6DA,MAAMA,2BAA2B,CAC/BC,GAAAA,GAEA,YAAYA,GACZ,IAAA,OAAOA,IAAIC,MAAM,KAAK,YACtB,CAACC,KAAAA,CAAMC,OAAO,CAACH,GAAAA,CAA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ACEC,cAAQD,CAAAA,GAAAA,CAAAA,IACR,MAAUA,IAAAA,GAAAA,KACTA,GAAAA,CAAIE,IAAI,KAAK,kBAAsBF,IAAAA,GAAAA,CAAIE,IAAI,KAAK,+BAA8B,CAC/E,EAAA;AACA;;;AAGC,cACD,OAAO,KAAA;AACT;YAEA,MAAMF,GAAAA;AACR;AACF,KAAA,CAAA,CACCG,GAAG,CAAC,CAAChB,MAAAA,IAAY;AAChB,YAAA,GAAGA,MAAM;AACT3B,YAAAA,UAAAA,EAAY,CAAC,EAAE2B,MAAO3B,CAAAA,UAAU,CAAC,CAAC,EAAEwB,iBAAiB,CAACG,MAAAA,CAAO3B,UAAU,CAAC,CAAC;SAC3E,CAAA,CAAA;AACJ;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugins.js","sources":["../../../../src/node/core/plugins.ts"],"sourcesContent":["import os from 'node:os';\nimport path from 'node:path';\nimport fs from 'node:fs';\nimport camelCase from 'lodash/camelCase';\nimport { env } from '@strapi/utils';\nimport { getModule, PackageJson } from './dependencies';\nimport { convertModulePathToSystemPath, convertSystemPathToModulePath, loadFile } from './files';\nimport type { BaseContext } from '../types';\nimport { isError } from './errors';\n\ninterface LocalPluginMeta {\n name: string;\n /**\n * camelCased version of the plugin name\n */\n importName: string;\n /**\n * The path to the plugin, relative to the app's root directory\n * in system format\n */\n path: string;\n /**\n * The path to the plugin, relative to the runtime directory\n * in module format (i.e. with forward slashes) because thats\n * where it should be used as an import\n */\n modulePath: string;\n type: 'local';\n}\n\ninterface ModulePluginMeta {\n name: string;\n /**\n * camelCased version of the plugin name\n */\n importName: string;\n /**\n * Modules don't have a path because we never resolve them to their node_modules\n * because we simply do not require it.\n */\n path?: never;\n /**\n * The path to the plugin, relative to the app's root directory\n * in module format (i.e. with forward slashes)\n */\n modulePath: string;\n type: 'module';\n}\n\ntype PluginMeta = LocalPluginMeta | ModulePluginMeta;\n\ninterface StrapiPlugin extends PackageJson {\n strapi: {\n description?: string;\n displayName?: string;\n kind: 'plugin';\n name?: string;\n required?: boolean;\n };\n}\n\nconst validatePackageHasStrapi = (\n pkg: PackageJson\n): pkg is PackageJson & { strapi: Record<string, unknown> } =>\n 'strapi' in pkg &&\n typeof pkg.strapi === 'object' &&\n !Array.isArray(pkg.strapi) &&\n pkg.strapi !== null;\n\nconst validatePackageIsPlugin = (pkg: PackageJson): pkg is StrapiPlugin =>\n validatePackageHasStrapi(pkg) && pkg.strapi.kind === 'plugin';\n\nconst getEnabledPlugins = async ({\n cwd,\n logger,\n runtimeDir,\n strapi,\n}: Pick<BaseContext, 'cwd' | 'logger' | 'strapi' | 'runtimeDir'>): Promise<\n Record<string, PluginMeta>\n> => {\n const plugins: Record<string, PluginMeta> = {};\n\n /**\n * This is the list of dependencies that are installed in the user's project.\n * It will include libraries like \"react\", so we need to collect the ones that\n * are plugins.\n */\n const deps = strapi.config.get('info.dependencies', {});\n\n logger.debug(\"Dependencies from user's project\", os.EOL, deps);\n\n for (const dep of Object.keys(deps)) {\n const pkg = await getModule(dep, cwd);\n\n if (pkg && validatePackageIsPlugin(pkg)) {\n const name = pkg.strapi.name || pkg.name;\n\n if (!name) {\n /**\n * Unlikely to happen, but you never know.\n */\n throw Error(\n \"You're trying to import a plugin that doesn't have a name – check the package.json of that plugin!\"\n );\n }\n\n plugins[name] = {\n name,\n importName: camelCase(name),\n type: 'module',\n modulePath: dep,\n };\n }\n }\n\n const userPluginsFile = await loadUserPluginsFile(strapi.dirs.app.config);\n\n logger.debug(\"User's plugins file\", os.EOL, userPluginsFile);\n\n for (const [userPluginName, userPluginConfig] of Object.entries(userPluginsFile)) {\n if (userPluginConfig.enabled && userPluginConfig.resolve) {\n const sysPath = convertModulePathToSystemPath(userPluginConfig.resolve);\n plugins[userPluginName] = {\n name: userPluginName,\n importName: camelCase(userPluginName),\n type: 'local',\n /**\n * User plugin paths are resolved from the entry point\n * of the app, because that's how you import them.\n */\n modulePath: convertSystemPathToModulePath(path.relative(runtimeDir, sysPath)),\n path: sysPath,\n };\n }\n }\n\n return plugins;\n};\n\nconst PLUGIN_CONFIGS = ['plugins.js', 'plugins.mjs', 'plugins.ts'];\n\ntype UserPluginConfigFile = Record<string, { enabled: boolean; resolve: string }>;\n\nconst loadUserPluginsFile = async (root: string): Promise<UserPluginConfigFile> => {\n for (const file of PLUGIN_CONFIGS) {\n const filePath = path.join(root, file);\n const configFile = await loadFile(filePath);\n\n if (configFile) {\n /**\n * Configs can be a function or they can be just an object!\n */\n return typeof configFile === 'function' ? configFile({ env }) : configFile;\n }\n }\n\n return {};\n};\n\nconst getMapOfPluginsWithAdmin = (plugins: Record<string, PluginMeta>) => {\n /**\n * This variable stores the import paths for plugins.\n * The keys are the module paths of the plugins, and the values are the paths\n * to the admin part of the plugins, which is either loaded from the\n * package.json exports or from the legacy strapi-admin.js file.\n */\n const pluginImportPaths: Record<string, string> = {};\n\n return Object.values(plugins)\n .filter((plugin) => {\n if (!plugin) {\n return false;\n }\n\n /**\n * There are two ways a plugin should be imported, either it's local to the strapi app,\n * or it's an actual npm module that's installed and resolved via node_modules.\n *\n * We first check if the plugin is local to the strapi app, using a regular `fs.existsSync` because\n * the pathToPlugin will be relative i.e. `/Users/my-name/strapi-app/src/plugins/my-plugin`.\n *\n * If the file doesn't exist well then it's probably a node_module, so instead we use `require.resolve`\n * which will resolve the path to the module in node_modules. If it fails with the specific code `MODULE_NOT_FOUND`\n * then it doesn't have an admin part to the package.\n */\n try {\n const localPluginPath = plugin.path;\n if (localPluginPath) {\n // Here we are loading a locally installed plugin\n const packageJsonPath = path.join(localPluginPath, 'package.json');\n\n if (fs.existsSync(packageJsonPath)) {\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));\n const localAdminPath = packageJson?.exports?.['./strapi-admin']?.import;\n\n if (localAdminPath) {\n pluginImportPaths[plugin.modulePath] = localAdminPath;\n return true;\n }\n }\n\n // Check if legacy admin file exists in local plugin\n if (fs.existsSync(path.join(localPluginPath, 'strapi-admin.js'))) {\n pluginImportPaths[plugin.modulePath] = 'strapi-admin';\n return true;\n }\n }\n\n // This plugin is a module, so we need to check if it has a strapi-admin export\n if (require.resolve(`${plugin.modulePath}/strapi-admin`)) {\n pluginImportPaths[plugin.modulePath] = 'strapi-admin';\n return true;\n }\n\n return false;\n } catch (err) {\n if (\n isError(err) &&\n 'code' in err &&\n (err.code === 'MODULE_NOT_FOUND' || err.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED')\n ) {\n /**\n * the plugin does not contain FE code, so we\n * don't want to import it anyway\n */\n return false;\n }\n\n throw err;\n }\n })\n .map((plugin) => ({\n ...plugin,\n modulePath: `${plugin.modulePath}/${pluginImportPaths[plugin.modulePath]}`,\n }));\n};\n\nexport { getEnabledPlugins, getMapOfPluginsWithAdmin };\nexport type { PluginMeta, LocalPluginMeta, ModulePluginMeta };\n"],"names":["validatePackageHasStrapi","pkg","strapi","Array","isArray","validatePackageIsPlugin","kind","getEnabledPlugins","cwd","logger","runtimeDir","plugins","deps","config","get","debug","os","EOL","dep","Object","keys","getModule","name","Error","importName","camelCase","type","modulePath","userPluginsFile","loadUserPluginsFile","dirs","app","userPluginName","userPluginConfig","entries","enabled","resolve","sysPath","convertModulePathToSystemPath","convertSystemPathToModulePath","path","relative","PLUGIN_CONFIGS","root","file","filePath","join","configFile","loadFile","env","getMapOfPluginsWithAdmin","pluginImportPaths","values","filter","plugin","localPluginPath","packageJsonPath","fs","existsSync","packageJson","JSON","parse","readFileSync","localAdminPath","exports","import","require","err","isError","code","map"],"mappings":";;;;;;;;;;;AA6DA,MAAMA,2BAA2B,CAC/BC,GAAAA,GAEA,YAAYA,GACZ,IAAA,OAAOA,IAAIC,MAAM,KAAK,YACtB,CAACC,KAAAA,CAAMC,OAAO,CAACH,GAAAA,CAAIC,MAAM,CACzBD,IAAAA,GAAAA,CAAIC,MAAM,KAAK,IAAA;AAEjB,MAAMG,uBAAAA,GAA0B,CAACJ,GAC/BD,GAAAA,wBAAAA,CAAyBC,QAAQA,GAAIC,CAAAA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C/E,EAAA;AACA;;;AAGC,cACD,OAAO,KAAA;AACT;YAEA,MAAMF,GAAAA;AACR;AACF,KAAA,CAAA,CACCG,GAAG,CAAC,CAAChB,MAAAA,IAAY;AAChB,YAAA,GAAGA,MAAM;YACT3B,UAAY,EAAA,CAAA,EAAG2B,MAAO3B,CAAAA,UAAU,CAAC,CAAC,EAAEwB,iBAAiB,CAACG,MAAAA,CAAO3B,UAAU,CAAC,CAAE;SAC5E,CAAA,CAAA;AACJ;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.mjs","sources":["../../../../src/node/core/plugins.ts"],"sourcesContent":["import os from 'node:os';\nimport path from 'node:path';\nimport fs from 'node:fs';\nimport camelCase from 'lodash/camelCase';\nimport { env } from '@strapi/utils';\nimport { getModule, PackageJson } from './dependencies';\nimport { convertModulePathToSystemPath, convertSystemPathToModulePath, loadFile } from './files';\nimport type { BaseContext } from '../types';\nimport { isError } from './errors';\n\ninterface LocalPluginMeta {\n name: string;\n /**\n * camelCased version of the plugin name\n */\n importName: string;\n /**\n * The path to the plugin, relative to the app's root directory\n * in system format\n */\n path: string;\n /**\n * The path to the plugin, relative to the runtime directory\n * in module format (i.e. with forward slashes) because thats\n * where it should be used as an import\n */\n modulePath: string;\n type: 'local';\n}\n\ninterface ModulePluginMeta {\n name: string;\n /**\n * camelCased version of the plugin name\n */\n importName: string;\n /**\n * Modules don't have a path because we never resolve them to their node_modules\n * because we simply do not require it.\n */\n path?: never;\n /**\n * The path to the plugin, relative to the app's root directory\n * in module format (i.e. with forward slashes)\n */\n modulePath: string;\n type: 'module';\n}\n\ntype PluginMeta = LocalPluginMeta | ModulePluginMeta;\n\ninterface StrapiPlugin extends PackageJson {\n strapi: {\n description?: string;\n displayName?: string;\n kind: 'plugin';\n name?: string;\n required?: boolean;\n };\n}\n\nconst validatePackageHasStrapi = (\n pkg: PackageJson\n): pkg is PackageJson & { strapi: Record<string, unknown> } =>\n 'strapi' in pkg &&\n typeof pkg.strapi === 'object' &&\n !Array.isArray(pkg.strapi) &&\n pkg.strapi !== null;\n\nconst validatePackageIsPlugin = (pkg: PackageJson): pkg is StrapiPlugin =>\n validatePackageHasStrapi(pkg) && pkg.strapi.kind === 'plugin';\n\nconst getEnabledPlugins = async ({\n cwd,\n logger,\n runtimeDir,\n strapi,\n}: Pick<BaseContext, 'cwd' | 'logger' | 'strapi' | 'runtimeDir'>): Promise<\n Record<string, PluginMeta>\n> => {\n const plugins: Record<string, PluginMeta> = {};\n\n /**\n * This is the list of dependencies that are installed in the user's project.\n * It will include libraries like \"react\", so we need to collect the ones that\n * are plugins.\n */\n const deps = strapi.config.get('info.dependencies', {});\n\n logger.debug(\"Dependencies from user's project\", os.EOL, deps);\n\n for (const dep of Object.keys(deps)) {\n const pkg = await getModule(dep, cwd);\n\n if (pkg && validatePackageIsPlugin(pkg)) {\n const name = pkg.strapi.name || pkg.name;\n\n if (!name) {\n /**\n * Unlikely to happen, but you never know.\n */\n throw Error(\n \"You're trying to import a plugin that doesn't have a name – check the package.json of that plugin!\"\n );\n }\n\n plugins[name] = {\n name,\n importName: camelCase(name),\n type: 'module',\n modulePath: dep,\n };\n }\n }\n\n const userPluginsFile = await loadUserPluginsFile(strapi.dirs.app.config);\n\n logger.debug(\"User's plugins file\", os.EOL, userPluginsFile);\n\n for (const [userPluginName, userPluginConfig] of Object.entries(userPluginsFile)) {\n if (userPluginConfig.enabled && userPluginConfig.resolve) {\n const sysPath = convertModulePathToSystemPath(userPluginConfig.resolve);\n plugins[userPluginName] = {\n name: userPluginName,\n importName: camelCase(userPluginName),\n type: 'local',\n /**\n * User plugin paths are resolved from the entry point\n * of the app, because that's how you import them.\n */\n modulePath: convertSystemPathToModulePath(path.relative(runtimeDir, sysPath)),\n path: sysPath,\n };\n }\n }\n\n return plugins;\n};\n\nconst PLUGIN_CONFIGS = ['plugins.js', 'plugins.mjs', 'plugins.ts'];\n\ntype UserPluginConfigFile = Record<string, { enabled: boolean; resolve: string }>;\n\nconst loadUserPluginsFile = async (root: string): Promise<UserPluginConfigFile> => {\n for (const file of PLUGIN_CONFIGS) {\n const filePath = path.join(root, file);\n const configFile = await loadFile(filePath);\n\n if (configFile) {\n /**\n * Configs can be a function or they can be just an object!\n */\n return typeof configFile === 'function' ? configFile({ env }) : configFile;\n }\n }\n\n return {};\n};\n\nconst getMapOfPluginsWithAdmin = (plugins: Record<string, PluginMeta>) => {\n /**\n * This variable stores the import paths for plugins.\n * The keys are the module paths of the plugins, and the values are the paths\n * to the admin part of the plugins, which is either loaded from the\n * package.json exports or from the legacy strapi-admin.js file.\n */\n const pluginImportPaths: Record<string, string> = {};\n\n return Object.values(plugins)\n .filter((plugin) => {\n if (!plugin) {\n return false;\n }\n\n /**\n * There are two ways a plugin should be imported, either it's local to the strapi app,\n * or it's an actual npm module that's installed and resolved via node_modules.\n *\n * We first check if the plugin is local to the strapi app, using a regular `fs.existsSync` because\n * the pathToPlugin will be relative i.e. `/Users/my-name/strapi-app/src/plugins/my-plugin`.\n *\n * If the file doesn't exist well then it's probably a node_module, so instead we use `require.resolve`\n * which will resolve the path to the module in node_modules. If it fails with the specific code `MODULE_NOT_FOUND`\n * then it doesn't have an admin part to the package.\n */\n try {\n const localPluginPath = plugin.path;\n if (localPluginPath) {\n // Here we are loading a locally installed plugin\n const packageJsonPath = path.join(localPluginPath, 'package.json');\n\n if (fs.existsSync(packageJsonPath)) {\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));\n const localAdminPath = packageJson?.exports?.['./strapi-admin']?.import;\n\n if (localAdminPath) {\n pluginImportPaths[plugin.modulePath] = localAdminPath;\n return true;\n }\n }\n\n // Check if legacy admin file exists in local plugin\n if (fs.existsSync(path.join(localPluginPath, 'strapi-admin.js'))) {\n pluginImportPaths[plugin.modulePath] = 'strapi-admin';\n return true;\n }\n }\n\n // This plugin is a module, so we need to check if it has a strapi-admin export\n if (require.resolve(`${plugin.modulePath}/strapi-admin`)) {\n pluginImportPaths[plugin.modulePath] = 'strapi-admin';\n return true;\n }\n\n return false;\n } catch (err) {\n if (\n isError(err) &&\n 'code' in err &&\n (err.code === 'MODULE_NOT_FOUND' || err.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED')\n ) {\n /**\n * the plugin does not contain FE code, so we\n * don't want to import it anyway\n */\n return false;\n }\n\n throw err;\n }\n })\n .map((plugin) => ({\n ...plugin,\n modulePath: `${plugin.modulePath}/${pluginImportPaths[plugin.modulePath]}`,\n }));\n};\n\nexport { getEnabledPlugins, getMapOfPluginsWithAdmin };\nexport type { PluginMeta, LocalPluginMeta, ModulePluginMeta };\n"],"names":["validatePackageHasStrapi","pkg","strapi","Array","isArray","validatePackageIsPlugin","kind","getEnabledPlugins","cwd","logger","runtimeDir","plugins","deps","config","get","debug","os","EOL","dep","Object","keys","getModule","name","Error","importName","camelCase","type","modulePath","userPluginsFile","loadUserPluginsFile","dirs","app","userPluginName","userPluginConfig","entries","enabled","resolve","sysPath","convertModulePathToSystemPath","convertSystemPathToModulePath","path","relative","PLUGIN_CONFIGS","root","file","filePath","join","configFile","loadFile","env","getMapOfPluginsWithAdmin","pluginImportPaths","values","filter","plugin","localPluginPath","packageJsonPath","fs","existsSync","packageJson","JSON","parse","readFileSync","localAdminPath","exports","import","require","err","isError","code","map"],"mappings":";;;;;;;;;AA6DA,MAAMA,2BAA2B,CAC/BC,GAAAA,GAEA,YAAYA,GACZ,IAAA,OAAOA,IAAIC,MAAM,KAAK,YACtB,CAACC,KAAAA,CAAMC,OAAO,CAACH,GAAAA,CAAIC,MAAM,CACzBD,IAAAA,GAAAA,CAAIC,MAAM,KAAK,IAAA;AAEjB,MAAMG,uBAAAA,GAA0B,CAACJ,GAC/BD,GAAAA,wBAAAA,CAAyBC,QAAQA,GAAIC,CAAAA,MAAM,CAACI,IAAI,KAAK,QAAA;AAEjDC,MAAAA,iBAAAA,GAAoB,OAAO,EAC/BC,GAAG,EACHC,MAAM,EACNC,UAAU,EACVR,MAAM,EACwD,GAAA;AA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AA,GAAGA,MAAM;AACT3B,YAAAA,UAAAA,EAAY,CAAC,EAAE2B,MAAO3B,CAAAA,UAAU,CAAC,CAAC,EAAEwB,iBAAiB,CAACG,MAAAA,CAAO3B,UAAU,CAAC,CAAC;SAC3E,CAAA,CAAA;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"plugins.mjs","sources":["../../../../src/node/core/plugins.ts"],"sourcesContent":["import os from 'node:os';\nimport path from 'node:path';\nimport fs from 'node:fs';\nimport camelCase from 'lodash/camelCase';\nimport { env } from '@strapi/utils';\nimport { getModule, PackageJson } from './dependencies';\nimport { convertModulePathToSystemPath, convertSystemPathToModulePath, loadFile } from './files';\nimport type { BaseContext } from '../types';\nimport { isError } from './errors';\n\ninterface LocalPluginMeta {\n name: string;\n /**\n * camelCased version of the plugin name\n */\n importName: string;\n /**\n * The path to the plugin, relative to the app's root directory\n * in system format\n */\n path: string;\n /**\n * The path to the plugin, relative to the runtime directory\n * in module format (i.e. with forward slashes) because thats\n * where it should be used as an import\n */\n modulePath: string;\n type: 'local';\n}\n\ninterface ModulePluginMeta {\n name: string;\n /**\n * camelCased version of the plugin name\n */\n importName: string;\n /**\n * Modules don't have a path because we never resolve them to their node_modules\n * because we simply do not require it.\n */\n path?: never;\n /**\n * The path to the plugin, relative to the app's root directory\n * in module format (i.e. with forward slashes)\n */\n modulePath: string;\n type: 'module';\n}\n\ntype PluginMeta = LocalPluginMeta | ModulePluginMeta;\n\ninterface StrapiPlugin extends PackageJson {\n strapi: {\n description?: string;\n displayName?: string;\n kind: 'plugin';\n name?: string;\n required?: boolean;\n };\n}\n\nconst validatePackageHasStrapi = (\n pkg: PackageJson\n): pkg is PackageJson & { strapi: Record<string, unknown> } =>\n 'strapi' in pkg &&\n typeof pkg.strapi === 'object' &&\n !Array.isArray(pkg.strapi) &&\n pkg.strapi !== null;\n\nconst validatePackageIsPlugin = (pkg: PackageJson): pkg is StrapiPlugin =>\n validatePackageHasStrapi(pkg) && pkg.strapi.kind === 'plugin';\n\nconst getEnabledPlugins = async ({\n cwd,\n logger,\n runtimeDir,\n strapi,\n}: Pick<BaseContext, 'cwd' | 'logger' | 'strapi' | 'runtimeDir'>): Promise<\n Record<string, PluginMeta>\n> => {\n const plugins: Record<string, PluginMeta> = {};\n\n /**\n * This is the list of dependencies that are installed in the user's project.\n * It will include libraries like \"react\", so we need to collect the ones that\n * are plugins.\n */\n const deps = strapi.config.get('info.dependencies', {});\n\n logger.debug(\"Dependencies from user's project\", os.EOL, deps);\n\n for (const dep of Object.keys(deps)) {\n const pkg = await getModule(dep, cwd);\n\n if (pkg && validatePackageIsPlugin(pkg)) {\n const name = pkg.strapi.name || pkg.name;\n\n if (!name) {\n /**\n * Unlikely to happen, but you never know.\n */\n throw Error(\n \"You're trying to import a plugin that doesn't have a name – check the package.json of that plugin!\"\n );\n }\n\n plugins[name] = {\n name,\n importName: camelCase(name),\n type: 'module',\n modulePath: dep,\n };\n }\n }\n\n const userPluginsFile = await loadUserPluginsFile(strapi.dirs.app.config);\n\n logger.debug(\"User's plugins file\", os.EOL, userPluginsFile);\n\n for (const [userPluginName, userPluginConfig] of Object.entries(userPluginsFile)) {\n if (userPluginConfig.enabled && userPluginConfig.resolve) {\n const sysPath = convertModulePathToSystemPath(userPluginConfig.resolve);\n plugins[userPluginName] = {\n name: userPluginName,\n importName: camelCase(userPluginName),\n type: 'local',\n /**\n * User plugin paths are resolved from the entry point\n * of the app, because that's how you import them.\n */\n modulePath: convertSystemPathToModulePath(path.relative(runtimeDir, sysPath)),\n path: sysPath,\n };\n }\n }\n\n return plugins;\n};\n\nconst PLUGIN_CONFIGS = ['plugins.js', 'plugins.mjs', 'plugins.ts'];\n\ntype UserPluginConfigFile = Record<string, { enabled: boolean; resolve: string }>;\n\nconst loadUserPluginsFile = async (root: string): Promise<UserPluginConfigFile> => {\n for (const file of PLUGIN_CONFIGS) {\n const filePath = path.join(root, file);\n const configFile = await loadFile(filePath);\n\n if (configFile) {\n /**\n * Configs can be a function or they can be just an object!\n */\n return typeof configFile === 'function' ? configFile({ env }) : configFile;\n }\n }\n\n return {};\n};\n\nconst getMapOfPluginsWithAdmin = (plugins: Record<string, PluginMeta>) => {\n /**\n * This variable stores the import paths for plugins.\n * The keys are the module paths of the plugins, and the values are the paths\n * to the admin part of the plugins, which is either loaded from the\n * package.json exports or from the legacy strapi-admin.js file.\n */\n const pluginImportPaths: Record<string, string> = {};\n\n return Object.values(plugins)\n .filter((plugin) => {\n if (!plugin) {\n return false;\n }\n\n /**\n * There are two ways a plugin should be imported, either it's local to the strapi app,\n * or it's an actual npm module that's installed and resolved via node_modules.\n *\n * We first check if the plugin is local to the strapi app, using a regular `fs.existsSync` because\n * the pathToPlugin will be relative i.e. `/Users/my-name/strapi-app/src/plugins/my-plugin`.\n *\n * If the file doesn't exist well then it's probably a node_module, so instead we use `require.resolve`\n * which will resolve the path to the module in node_modules. If it fails with the specific code `MODULE_NOT_FOUND`\n * then it doesn't have an admin part to the package.\n */\n try {\n const localPluginPath = plugin.path;\n if (localPluginPath) {\n // Here we are loading a locally installed plugin\n const packageJsonPath = path.join(localPluginPath, 'package.json');\n\n if (fs.existsSync(packageJsonPath)) {\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));\n const localAdminPath = packageJson?.exports?.['./strapi-admin']?.import;\n\n if (localAdminPath) {\n pluginImportPaths[plugin.modulePath] = localAdminPath;\n return true;\n }\n }\n\n // Check if legacy admin file exists in local plugin\n if (fs.existsSync(path.join(localPluginPath, 'strapi-admin.js'))) {\n pluginImportPaths[plugin.modulePath] = 'strapi-admin';\n return true;\n }\n }\n\n // This plugin is a module, so we need to check if it has a strapi-admin export\n if (require.resolve(`${plugin.modulePath}/strapi-admin`)) {\n pluginImportPaths[plugin.modulePath] = 'strapi-admin';\n return true;\n }\n\n return false;\n } catch (err) {\n if (\n isError(err) &&\n 'code' in err &&\n (err.code === 'MODULE_NOT_FOUND' || err.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED')\n ) {\n /**\n * the plugin does not contain FE code, so we\n * don't want to import it anyway\n */\n return false;\n }\n\n throw err;\n }\n })\n .map((plugin) => ({\n ...plugin,\n modulePath: `${plugin.modulePath}/${pluginImportPaths[plugin.modulePath]}`,\n }));\n};\n\nexport { getEnabledPlugins, getMapOfPluginsWithAdmin };\nexport type { PluginMeta, LocalPluginMeta, ModulePluginMeta };\n"],"names":["validatePackageHasStrapi","pkg","strapi","Array","isArray","validatePackageIsPlugin","kind","getEnabledPlugins","cwd","logger","runtimeDir","plugins","deps","config","get","debug","os","EOL","dep","Object","keys","getModule","name","Error","importName","camelCase","type","modulePath","userPluginsFile","loadUserPluginsFile","dirs","app","userPluginName","userPluginConfig","entries","enabled","resolve","sysPath","convertModulePathToSystemPath","convertSystemPathToModulePath","path","relative","PLUGIN_CONFIGS","root","file","filePath","join","configFile","loadFile","env","getMapOfPluginsWithAdmin","pluginImportPaths","values","filter","plugin","localPluginPath","packageJsonPath","fs","existsSync","packageJson","JSON","parse","readFileSync","localAdminPath","exports","import","require","err","isError","code","map"],"mappings":";;;;;;;;;AA6DA,MAAMA,2BAA2B,CAC/BC,GAAAA,GAEA,YAAYA,GACZ,IAAA,OAAOA,IAAIC,MAAM,KAAK,YACtB,CAACC,KAAAA,CAAMC,OAAO,CAACH,GAAAA,CAAIC,MAAM,CACzBD,IAAAA,GAAAA,CAAIC,MAAM,KAAK,IAAA;AAEjB,MAAMG,uBAAAA,GAA0B,CAACJ,GAC/BD,GAAAA,wBAAAA,CAAyBC,QAAQA,GAAIC,CAAAA,MAAM,CAACI,IAAI,KAAK,QAAA;AAEjDC,MAAAA,iBAAAA,GAAoB,OAAO,EAC/BC,GAAG,EACHC,MAAM,EACNC,UAAU,EACVR,MAAM,EACwD,GAAA;AAG9D,IAAA,MAAMS,UAAsC,EAAC;AAE7C;;;;MAKA,MAAMC,OAAOV,MAAOW,CAAAA,MAAM,CAACC,GAAG,CAAC,qBAAqB,EAAC,CAAA;AAErDL,IAAAA,MAAAA,CAAOM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AAA,CAAA;AACJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timer.js","sources":["../../../../src/node/core/timer.ts"],"sourcesContent":["import { performance } from 'perf_hooks';\n\nexport interface TimeMeasurer {\n start: (name: string) => void;\n end: (name: string) => number;\n getTimings: () => Record<string, number>;\n}\n\nexport function getTimer(): TimeMeasurer {\n const timings: Record<string, number> = {};\n const startTimes: Record<string, number> = {};\n\n function start(name: string): void {\n if (typeof startTimes[name] !== 'undefined') {\n throw new Error(`Timer \"${name}\" already started, cannot overwrite`);\n }\n\n startTimes[name] = performance.now();\n }\n\n function end(name: string): number {\n if (typeof startTimes[name] === 'undefined') {\n throw new Error(`Timer \"${name}\" never started, cannot end`);\n }\n\n timings[name] = performance.now() - startTimes[name];\n return timings[name];\n }\n\n return { start, end, getTimings: () => timings };\n}\n\nexport const prettyTime = (timeInMs: number): string => {\n return `${Math.ceil(timeInMs)}ms`;\n};\n"],"names":["getTimer","timings","startTimes","start","name","Error","performance","now","end","getTimings","prettyTime","timeInMs","Math","ceil"],"mappings":";;;;AAQO,SAASA,QAAAA,GAAAA;AACd,IAAA,MAAMC,UAAkC,EAAC;AACzC,IAAA,MAAMC,aAAqC,EAAC;AAE5C,IAAA,SAASC,MAAMC,IAAY,EAAA;AACzB,QAAA,IAAI,OAAOF,UAAU,CAACE,IAAAA,CAAK,KAAK,WAAa,EAAA;AAC3C,YAAA,MAAM,IAAIC,KAAM,CAAA,CAAC,OAAO,EAAED,IAAAA,CAAK,mCAAmC,CAAC,CAAA;AACrE;AAEAF,QAAAA,UAAU,CAACE,IAAAA,CAAK,GAAGE,sBAAAA,CAAYC,GAAG,EAAA;AACpC;AAEA,IAAA,SAASC,IAAIJ,IAAY,EAAA;AACvB,QAAA,IAAI,OAAOF,UAAU,CAACE,IAAAA,CAAK,KAAK,WAAa,EAAA;AAC3C,YAAA,MAAM,IAAIC,KAAM,CAAA,CAAC,OAAO,EAAED,IAAAA,CAAK,2BAA2B,CAAC,CAAA;AAC7D;QAEAH,OAAO,CAACG,KAAK,GAAGE,sBAAAA,CAAYC,GAAG,EAAKL,GAAAA,UAAU,CAACE,IAAK,CAAA;QACpD,OAAOH,OAAO,CAACG,IAAK,CAAA;AACtB;IAEA,OAAO;AAAED,QAAAA,KAAAA;AAAOK,QAAAA,GAAAA;AAAKC,QAAAA,UAAAA,EAAY,IAAMR;AAAQ,KAAA;AACjD;AAEO,MAAMS,aAAa,CAACC,QAAAA,GAAAA;AACzB,IAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"timer.js","sources":["../../../../src/node/core/timer.ts"],"sourcesContent":["import { performance } from 'perf_hooks';\n\nexport interface TimeMeasurer {\n start: (name: string) => void;\n end: (name: string) => number;\n getTimings: () => Record<string, number>;\n}\n\nexport function getTimer(): TimeMeasurer {\n const timings: Record<string, number> = {};\n const startTimes: Record<string, number> = {};\n\n function start(name: string): void {\n if (typeof startTimes[name] !== 'undefined') {\n throw new Error(`Timer \"${name}\" already started, cannot overwrite`);\n }\n\n startTimes[name] = performance.now();\n }\n\n function end(name: string): number {\n if (typeof startTimes[name] === 'undefined') {\n throw new Error(`Timer \"${name}\" never started, cannot end`);\n }\n\n timings[name] = performance.now() - startTimes[name];\n return timings[name];\n }\n\n return { start, end, getTimings: () => timings };\n}\n\nexport const prettyTime = (timeInMs: number): string => {\n return `${Math.ceil(timeInMs)}ms`;\n};\n"],"names":["getTimer","timings","startTimes","start","name","Error","performance","now","end","getTimings","prettyTime","timeInMs","Math","ceil"],"mappings":";;;;AAQO,SAASA,QAAAA,GAAAA;AACd,IAAA,MAAMC,UAAkC,EAAC;AACzC,IAAA,MAAMC,aAAqC,EAAC;AAE5C,IAAA,SAASC,MAAMC,IAAY,EAAA;AACzB,QAAA,IAAI,OAAOF,UAAU,CAACE,IAAAA,CAAK,KAAK,WAAa,EAAA;AAC3C,YAAA,MAAM,IAAIC,KAAM,CAAA,CAAC,OAAO,EAAED,IAAAA,CAAK,mCAAmC,CAAC,CAAA;AACrE;AAEAF,QAAAA,UAAU,CAACE,IAAAA,CAAK,GAAGE,sBAAAA,CAAYC,GAAG,EAAA;AACpC;AAEA,IAAA,SAASC,IAAIJ,IAAY,EAAA;AACvB,QAAA,IAAI,OAAOF,UAAU,CAACE,IAAAA,CAAK,KAAK,WAAa,EAAA;AAC3C,YAAA,MAAM,IAAIC,KAAM,CAAA,CAAC,OAAO,EAAED,IAAAA,CAAK,2BAA2B,CAAC,CAAA;AAC7D;QAEAH,OAAO,CAACG,KAAK,GAAGE,sBAAAA,CAAYC,GAAG,EAAKL,GAAAA,UAAU,CAACE,IAAK,CAAA;QACpD,OAAOH,OAAO,CAACG,IAAK,CAAA;AACtB;IAEA,OAAO;AAAED,QAAAA,KAAAA;AAAOK,QAAAA,GAAAA;AAAKC,QAAAA,UAAAA,EAAY,IAAMR;AAAQ,KAAA;AACjD;AAEO,MAAMS,aAAa,CAACC,QAAAA,GAAAA;AACzB,IAAA,OAAO,GAAGC,IAAKC,CAAAA,IAAI,CAACF,QAAAA,CAAAA,CAAU,EAAE,CAAC;AACnC;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timer.mjs","sources":["../../../../src/node/core/timer.ts"],"sourcesContent":["import { performance } from 'perf_hooks';\n\nexport interface TimeMeasurer {\n start: (name: string) => void;\n end: (name: string) => number;\n getTimings: () => Record<string, number>;\n}\n\nexport function getTimer(): TimeMeasurer {\n const timings: Record<string, number> = {};\n const startTimes: Record<string, number> = {};\n\n function start(name: string): void {\n if (typeof startTimes[name] !== 'undefined') {\n throw new Error(`Timer \"${name}\" already started, cannot overwrite`);\n }\n\n startTimes[name] = performance.now();\n }\n\n function end(name: string): number {\n if (typeof startTimes[name] === 'undefined') {\n throw new Error(`Timer \"${name}\" never started, cannot end`);\n }\n\n timings[name] = performance.now() - startTimes[name];\n return timings[name];\n }\n\n return { start, end, getTimings: () => timings };\n}\n\nexport const prettyTime = (timeInMs: number): string => {\n return `${Math.ceil(timeInMs)}ms`;\n};\n"],"names":["getTimer","timings","startTimes","start","name","Error","performance","now","end","getTimings","prettyTime","timeInMs","Math","ceil"],"mappings":";;AAQO,SAASA,QAAAA,GAAAA;AACd,IAAA,MAAMC,UAAkC,EAAC;AACzC,IAAA,MAAMC,aAAqC,EAAC;AAE5C,IAAA,SAASC,MAAMC,IAAY,EAAA;AACzB,QAAA,IAAI,OAAOF,UAAU,CAACE,IAAAA,CAAK,KAAK,WAAa,EAAA;AAC3C,YAAA,MAAM,IAAIC,KAAM,CAAA,CAAC,OAAO,EAAED,IAAAA,CAAK,mCAAmC,CAAC,CAAA;AACrE;AAEAF,QAAAA,UAAU,CAACE,IAAAA,CAAK,GAAGE,WAAAA,CAAYC,GAAG,EAAA;AACpC;AAEA,IAAA,SAASC,IAAIJ,IAAY,EAAA;AACvB,QAAA,IAAI,OAAOF,UAAU,CAACE,IAAAA,CAAK,KAAK,WAAa,EAAA;AAC3C,YAAA,MAAM,IAAIC,KAAM,CAAA,CAAC,OAAO,EAAED,IAAAA,CAAK,2BAA2B,CAAC,CAAA;AAC7D;QAEAH,OAAO,CAACG,KAAK,GAAGE,WAAAA,CAAYC,GAAG,EAAKL,GAAAA,UAAU,CAACE,IAAK,CAAA;QACpD,OAAOH,OAAO,CAACG,IAAK,CAAA;AACtB;IAEA,OAAO;AAAED,QAAAA,KAAAA;AAAOK,QAAAA,GAAAA;AAAKC,QAAAA,UAAAA,EAAY,IAAMR;AAAQ,KAAA;AACjD;AAEO,MAAMS,aAAa,CAACC,QAAAA,GAAAA;AACzB,IAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"timer.mjs","sources":["../../../../src/node/core/timer.ts"],"sourcesContent":["import { performance } from 'perf_hooks';\n\nexport interface TimeMeasurer {\n start: (name: string) => void;\n end: (name: string) => number;\n getTimings: () => Record<string, number>;\n}\n\nexport function getTimer(): TimeMeasurer {\n const timings: Record<string, number> = {};\n const startTimes: Record<string, number> = {};\n\n function start(name: string): void {\n if (typeof startTimes[name] !== 'undefined') {\n throw new Error(`Timer \"${name}\" already started, cannot overwrite`);\n }\n\n startTimes[name] = performance.now();\n }\n\n function end(name: string): number {\n if (typeof startTimes[name] === 'undefined') {\n throw new Error(`Timer \"${name}\" never started, cannot end`);\n }\n\n timings[name] = performance.now() - startTimes[name];\n return timings[name];\n }\n\n return { start, end, getTimings: () => timings };\n}\n\nexport const prettyTime = (timeInMs: number): string => {\n return `${Math.ceil(timeInMs)}ms`;\n};\n"],"names":["getTimer","timings","startTimes","start","name","Error","performance","now","end","getTimings","prettyTime","timeInMs","Math","ceil"],"mappings":";;AAQO,SAASA,QAAAA,GAAAA;AACd,IAAA,MAAMC,UAAkC,EAAC;AACzC,IAAA,MAAMC,aAAqC,EAAC;AAE5C,IAAA,SAASC,MAAMC,IAAY,EAAA;AACzB,QAAA,IAAI,OAAOF,UAAU,CAACE,IAAAA,CAAK,KAAK,WAAa,EAAA;AAC3C,YAAA,MAAM,IAAIC,KAAM,CAAA,CAAC,OAAO,EAAED,IAAAA,CAAK,mCAAmC,CAAC,CAAA;AACrE;AAEAF,QAAAA,UAAU,CAACE,IAAAA,CAAK,GAAGE,WAAAA,CAAYC,GAAG,EAAA;AACpC;AAEA,IAAA,SAASC,IAAIJ,IAAY,EAAA;AACvB,QAAA,IAAI,OAAOF,UAAU,CAACE,IAAAA,CAAK,KAAK,WAAa,EAAA;AAC3C,YAAA,MAAM,IAAIC,KAAM,CAAA,CAAC,OAAO,EAAED,IAAAA,CAAK,2BAA2B,CAAC,CAAA;AAC7D;QAEAH,OAAO,CAACG,KAAK,GAAGE,WAAAA,CAAYC,GAAG,EAAKL,GAAAA,UAAU,CAACE,IAAK,CAAA;QACpD,OAAOH,OAAO,CAACG,IAAK,CAAA;AACtB;IAEA,OAAO;AAAED,QAAAA,KAAAA;AAAOK,QAAAA,GAAAA;AAAKC,QAAAA,UAAAA,EAAY,IAAMR;AAAQ,KAAA;AACjD;AAEO,MAAMS,aAAa,CAACC,QAAAA,GAAAA;AACzB,IAAA,OAAO,GAAGC,IAAKC,CAAAA,IAAI,CAACF,QAAAA,CAAAA,CAAU,EAAE,CAAC;AACnC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-build-context.js","sources":["../../../src/node/create-build-context.ts"],"sourcesContent":["import os from 'node:os';\nimport path from 'node:path';\nimport fs from 'node:fs/promises';\nimport browserslist from 'browserslist';\nimport { createStrapi } from '@strapi/core';\nimport type { Core, Modules } from '@strapi/types';\nimport type { Server } from 'node:http';\n\nimport type { CLIContext } from '../cli/types';\nimport { getStrapiAdminEnvVars, loadEnv } from './core/env';\n\nimport { PluginMeta, getEnabledPlugins, getMapOfPluginsWithAdmin } from './core/plugins';\nimport { AppFile, loadUserAppFile } from './core/admin-customisations';\nimport type { BaseContext } from './types';\n\ninterface BaseOptions {\n stats?: boolean;\n minify?: boolean;\n sourcemaps?: boolean;\n bundler?: 'webpack' | 'vite';\n open?: boolean;\n hmrServer?: Server;\n hmrClientPort?: number;\n}\n\ninterface BuildContext<TOptions = unknown> extends BaseContext {\n /**\n * The customisations defined by the user in their app.js file\n */\n customisations?: AppFile;\n /**\n * Features object with future flags\n */\n features?: Modules.Features.FeaturesService['config'];\n /**\n * The build options\n */\n options: BaseOptions & TOptions;\n /**\n * The plugins to be included in the JS bundle\n * incl. internal plugins, third party plugins & local plugins\n */\n plugins: PluginMeta[];\n}\n\ninterface CreateBuildContextArgs<TOptions = unknown> extends CLIContext {\n strapi?: Core.Strapi;\n options?: TOptions;\n}\n\nconst DEFAULT_BROWSERSLIST = [\n 'last 3 major versions',\n 'Firefox ESR',\n 'last 2 Opera versions',\n 'not dead',\n];\n\nconst createBuildContext = async <TOptions extends BaseOptions>({\n cwd,\n logger,\n tsconfig,\n strapi,\n options = {} as TOptions,\n}: CreateBuildContextArgs<TOptions>): Promise<BuildContext<TOptions>> => {\n /**\n * If you make a new strapi instance when one already exists,\n * you will overwrite the global and the app will _most likely_\n * crash and die.\n */\n const strapiInstance =\n strapi ??\n createStrapi({\n // Directories\n appDir: cwd,\n distDir: tsconfig?.config.options.outDir ?? '',\n // Options\n autoReload: true,\n serveAdminPanel: false,\n });\n\n const serverAbsoluteUrl = strapiInstance.config.get<string>('server.absoluteUrl');\n const adminAbsoluteUrl = strapiInstance.config.get<string>('admin.absoluteUrl');\n const adminPath = strapiInstance.config.get<string>('admin.path');\n\n // NOTE: Checks that both the server and admin will be served from the same origin (protocol, host, port)\n const sameOrigin = new URL(adminAbsoluteUrl).origin === new URL(serverAbsoluteUrl).origin;\n\n const adminPublicPath = new URL(adminAbsoluteUrl).pathname;\n const serverPublicPath = new URL(serverAbsoluteUrl).pathname;\n\n const appDir = strapiInstance.dirs.app.root;\n\n await loadEnv(cwd);\n\n const env = getStrapiAdminEnvVars({\n ADMIN_PATH: adminPublicPath,\n STRAPI_ADMIN_BACKEND_URL: sameOrigin ? serverPublicPath : serverAbsoluteUrl,\n STRAPI_TELEMETRY_DISABLED: String(strapiInstance.telemetry.isDisabled),\n // TODO: Get this url from a utility/consts rather than duplicating it in AIChat constants.ts\n STRAPI_AI_URL:\n process.env.STRAPI_AI_URL?.replace(/\\/+$/, '') ?? 'https://strapi-ai.apps.strapi.io',\n STRAPI_ANALYTICS_URL: process.env.STRAPI_ANALYTICS_URL || 'https://analytics.strapi.io',\n });\n\n const envKeys = Object.keys(env);\n\n if (envKeys.length > 0) {\n logger.info(\n [\n 'Including the following ENV variables as part of the JS bundle:',\n ...envKeys.map((key) => ` - ${key}`),\n ].join(os.EOL)\n );\n }\n\n const distPath = path.join(strapiInstance.dirs.dist.root, 'build');\n const distDir = path.relative(cwd, distPath);\n\n /**\n * If the distPath already exists, clean it\n */\n try {\n logger.debug(`Cleaning dist folder: ${distPath}`);\n await fs.rm(distPath, { recursive: true, force: true });\n logger.debug('Cleaned dist folder');\n } catch {\n // do nothing, it will fail if the folder does not exist\n logger.debug('There was no dist folder to clean');\n }\n\n const runtimeDir = path.join(cwd, '.strapi', 'client');\n const entry = path.relative(cwd, path.join(runtimeDir, 'app.js'));\n\n const plugins = await getEnabledPlugins({ cwd, logger, runtimeDir, strapi: strapiInstance });\n\n logger.debug('Enabled plugins', os.EOL, plugins);\n\n const pluginsWithFront = getMapOfPluginsWithAdmin(plugins);\n\n logger.debug('Enabled plugins with FE', os.EOL, pluginsWithFront);\n\n const target = browserslist.loadConfig({ path: cwd }) ?? DEFAULT_BROWSERSLIST;\n\n const customisations = await loadUserAppFile({ appDir, runtimeDir });\n\n const features = strapiInstance.config.get('features', undefined);\n\n const { bundler = 'vite', ...restOptions } = options;\n\n const buildContext = {\n appDir,\n adminPath,\n basePath: adminPublicPath,\n bundler,\n customisations,\n cwd,\n distDir,\n distPath,\n entry,\n env,\n features,\n logger,\n options: restOptions as BaseOptions & TOptions,\n plugins: pluginsWithFront,\n runtimeDir,\n strapi: strapiInstance,\n target,\n tsconfig,\n } satisfies BuildContext<TOptions>;\n\n return buildContext;\n};\n\nexport { createBuildContext };\nexport type { BuildContext, CreateBuildContextArgs };\n"],"names":["DEFAULT_BROWSERSLIST","createBuildContext","cwd","logger","tsconfig","strapi","options","strapiInstance","createStrapi","appDir","distDir","config","outDir","autoReload","serveAdminPanel","serverAbsoluteUrl","get","adminAbsoluteUrl","adminPath","sameOrigin","URL","origin","adminPublicPath","pathname","serverPublicPath","dirs","app","root","loadEnv","env","getStrapiAdminEnvVars","ADMIN_PATH","STRAPI_ADMIN_BACKEND_URL","STRAPI_TELEMETRY_DISABLED","String","telemetry","isDisabled","STRAPI_AI_URL","process","replace","STRAPI_ANALYTICS_URL","envKeys","Object","keys","length","info","map","key","join","os","EOL","distPath","path","dist","relative","debug","fs","rm","recursive","force","runtimeDir","entry","plugins","getEnabledPlugins","pluginsWithFront","getMapOfPluginsWithAdmin","target","browserslist","loadConfig","customisations","loadUserAppFile","features","undefined","bundler","restOptions","buildContext","basePath"],"mappings":";;;;;;;;;;;AAkDA,MAAMA,oBAAuB,GAAA;AAC3B,IAAA,uBAAA;AACA,IAAA,aAAA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;AAC1DkB,QAAAA,yBAAAA,EAA2BC,MAAO3B,CAAAA,cAAAA,CAAe4B,SAAS,CAACC,UAAU,CAAA;;AAErEC,QAAAA,aAAAA,EACEC,QAAQT,GAAG,CAACQ,aAAa,EAAEE,OAAAA,CAAQ,QAAQ,EAAO,CAAA,IAAA,kCAAA;AACpDC,QAAAA,oBAAAA,EAAsBF,OAAQT,CAAAA,GAAG,CAACW,oBAAoB,IAAI;AAC5D,KAAA,CAAA;IAEA,MAAMC,OAAAA,GAAUC,MAAOC,CAAAA,IAAI,CAACd,KAAAA,CAAAA;IAE5B,IAAIY,OAAAA,CAAQG,MAAM,GAAG,CAAG,EAAA;AACtBzC,QAAAA,MAAAA,CAAO0C,IAAI,CACT;AACE,YAAA,iEAAA;
|
|
1
|
+
{"version":3,"file":"create-build-context.js","sources":["../../../src/node/create-build-context.ts"],"sourcesContent":["import os from 'node:os';\nimport path from 'node:path';\nimport fs from 'node:fs/promises';\nimport browserslist from 'browserslist';\nimport { createStrapi } from '@strapi/core';\nimport type { Core, Modules } from '@strapi/types';\nimport type { Server } from 'node:http';\n\nimport type { CLIContext } from '../cli/types';\nimport { getStrapiAdminEnvVars, loadEnv } from './core/env';\n\nimport { PluginMeta, getEnabledPlugins, getMapOfPluginsWithAdmin } from './core/plugins';\nimport { AppFile, loadUserAppFile } from './core/admin-customisations';\nimport type { BaseContext } from './types';\n\ninterface BaseOptions {\n stats?: boolean;\n minify?: boolean;\n sourcemaps?: boolean;\n bundler?: 'webpack' | 'vite';\n open?: boolean;\n hmrServer?: Server;\n hmrClientPort?: number;\n}\n\ninterface BuildContext<TOptions = unknown> extends BaseContext {\n /**\n * The customisations defined by the user in their app.js file\n */\n customisations?: AppFile;\n /**\n * Features object with future flags\n */\n features?: Modules.Features.FeaturesService['config'];\n /**\n * The build options\n */\n options: BaseOptions & TOptions;\n /**\n * The plugins to be included in the JS bundle\n * incl. internal plugins, third party plugins & local plugins\n */\n plugins: PluginMeta[];\n}\n\ninterface CreateBuildContextArgs<TOptions = unknown> extends CLIContext {\n strapi?: Core.Strapi;\n options?: TOptions;\n}\n\nconst DEFAULT_BROWSERSLIST = [\n 'last 3 major versions',\n 'Firefox ESR',\n 'last 2 Opera versions',\n 'not dead',\n];\n\nconst createBuildContext = async <TOptions extends BaseOptions>({\n cwd,\n logger,\n tsconfig,\n strapi,\n options = {} as TOptions,\n}: CreateBuildContextArgs<TOptions>): Promise<BuildContext<TOptions>> => {\n /**\n * If you make a new strapi instance when one already exists,\n * you will overwrite the global and the app will _most likely_\n * crash and die.\n */\n const strapiInstance =\n strapi ??\n createStrapi({\n // Directories\n appDir: cwd,\n distDir: tsconfig?.config.options.outDir ?? '',\n // Options\n autoReload: true,\n serveAdminPanel: false,\n });\n\n const serverAbsoluteUrl = strapiInstance.config.get<string>('server.absoluteUrl');\n const adminAbsoluteUrl = strapiInstance.config.get<string>('admin.absoluteUrl');\n const adminPath = strapiInstance.config.get<string>('admin.path');\n\n // NOTE: Checks that both the server and admin will be served from the same origin (protocol, host, port)\n const sameOrigin = new URL(adminAbsoluteUrl).origin === new URL(serverAbsoluteUrl).origin;\n\n const adminPublicPath = new URL(adminAbsoluteUrl).pathname;\n const serverPublicPath = new URL(serverAbsoluteUrl).pathname;\n\n const appDir = strapiInstance.dirs.app.root;\n\n await loadEnv(cwd);\n\n const env = getStrapiAdminEnvVars({\n ADMIN_PATH: adminPublicPath,\n STRAPI_ADMIN_BACKEND_URL: sameOrigin ? serverPublicPath : serverAbsoluteUrl,\n STRAPI_TELEMETRY_DISABLED: String(strapiInstance.telemetry.isDisabled),\n // TODO: Get this url from a utility/consts rather than duplicating it in AIChat constants.ts\n STRAPI_AI_URL:\n process.env.STRAPI_AI_URL?.replace(/\\/+$/, '') ?? 'https://strapi-ai.apps.strapi.io',\n STRAPI_ANALYTICS_URL: process.env.STRAPI_ANALYTICS_URL || 'https://analytics.strapi.io',\n });\n\n const envKeys = Object.keys(env);\n\n if (envKeys.length > 0) {\n logger.info(\n [\n 'Including the following ENV variables as part of the JS bundle:',\n ...envKeys.map((key) => ` - ${key}`),\n ].join(os.EOL)\n );\n }\n\n const distPath = path.join(strapiInstance.dirs.dist.root, 'build');\n const distDir = path.relative(cwd, distPath);\n\n /**\n * If the distPath already exists, clean it\n */\n try {\n logger.debug(`Cleaning dist folder: ${distPath}`);\n await fs.rm(distPath, { recursive: true, force: true });\n logger.debug('Cleaned dist folder');\n } catch {\n // do nothing, it will fail if the folder does not exist\n logger.debug('There was no dist folder to clean');\n }\n\n const runtimeDir = path.join(cwd, '.strapi', 'client');\n const entry = path.relative(cwd, path.join(runtimeDir, 'app.js'));\n\n const plugins = await getEnabledPlugins({ cwd, logger, runtimeDir, strapi: strapiInstance });\n\n logger.debug('Enabled plugins', os.EOL, plugins);\n\n const pluginsWithFront = getMapOfPluginsWithAdmin(plugins);\n\n logger.debug('Enabled plugins with FE', os.EOL, pluginsWithFront);\n\n const target = browserslist.loadConfig({ path: cwd }) ?? DEFAULT_BROWSERSLIST;\n\n const customisations = await loadUserAppFile({ appDir, runtimeDir });\n\n const features = strapiInstance.config.get('features', undefined);\n\n const { bundler = 'vite', ...restOptions } = options;\n\n const buildContext = {\n appDir,\n adminPath,\n basePath: adminPublicPath,\n bundler,\n customisations,\n cwd,\n distDir,\n distPath,\n entry,\n env,\n features,\n logger,\n options: restOptions as BaseOptions & TOptions,\n plugins: pluginsWithFront,\n runtimeDir,\n strapi: strapiInstance,\n target,\n tsconfig,\n } satisfies BuildContext<TOptions>;\n\n return buildContext;\n};\n\nexport { createBuildContext };\nexport type { BuildContext, CreateBuildContextArgs };\n"],"names":["DEFAULT_BROWSERSLIST","createBuildContext","cwd","logger","tsconfig","strapi","options","strapiInstance","createStrapi","appDir","distDir","config","outDir","autoReload","serveAdminPanel","serverAbsoluteUrl","get","adminAbsoluteUrl","adminPath","sameOrigin","URL","origin","adminPublicPath","pathname","serverPublicPath","dirs","app","root","loadEnv","env","getStrapiAdminEnvVars","ADMIN_PATH","STRAPI_ADMIN_BACKEND_URL","STRAPI_TELEMETRY_DISABLED","String","telemetry","isDisabled","STRAPI_AI_URL","process","replace","STRAPI_ANALYTICS_URL","envKeys","Object","keys","length","info","map","key","join","os","EOL","distPath","path","dist","relative","debug","fs","rm","recursive","force","runtimeDir","entry","plugins","getEnabledPlugins","pluginsWithFront","getMapOfPluginsWithAdmin","target","browserslist","loadConfig","customisations","loadUserAppFile","features","undefined","bundler","restOptions","buildContext","basePath"],"mappings":";;;;;;;;;;;AAkDA,MAAMA,oBAAuB,GAAA;AAC3B,IAAA,uBAAA;AACA,IAAA,aAAA;AACA,IAAA,uBAAA;AACA,IAAA;AACD,CAAA;AAED,MAAMC,kBAAqB,GAAA,OAAqC,EAC9DC,GAAG,EACHC,MAAM,EACNC,QAAQ,EACRC,MAAM,EACNC,OAAU,GAAA,EAAc,EACS,GAAA;AACjC;;;;MAKA,MAAMC,cACJF,GAAAA,MAAAA,IACAG,iBAAa,CAAA;;QAEXC,MAAQP,EAAAA,GAAAA;QACRQ,OAASN,EAAAA,QAAAA,EAAUO,MAAOL,CAAAA,OAAAA,CAAQM,MAAU,IAAA,EAAA;;QAE5CC,UAAY,EAAA,IAAA;QACZC,eAAiB,EAAA;AACnB,KAAA,CAAA;AAEF,IAAA,MAAMC,iBAAoBR,GAAAA,cAAAA,CAAeI,MAAM,CAACK,GAAG,CAAS,oBAAA,CAAA;AAC5D,IAAA,MAAMC,gBAAmBV,GAAAA,cAAAA,CAAeI,MAAM,CAACK,GAAG,CAAS,mBAAA,CAAA;AAC3D,IAAA,MAAME,SAAYX,GAAAA,cAAAA,CAAeI,MAAM,CAACK,GAAG,CAAS,YAAA,CAAA;;IAGpD,MAAMG,UAAAA,GAAa,IAAIC,GAAIH,CAAAA,gBAAAA,CAAAA,CAAkBI,MAAM,KAAK,IAAID,GAAIL,CAAAA,iBAAAA,CAAAA,CAAmBM,MAAM;AAEzF,IAAA,MAAMC,eAAkB,GAAA,IAAIF,GAAIH,CAAAA,gBAAAA,CAAAA,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cAAeI,CAAAA,MAAM,CAACK,GAAG,CAAC,UAAYwD,EAAAA,SAAAA,CAAAA;AAEvD,IAAA,MAAM,EAAEC,OAAU,GAAA,MAAM,EAAE,GAAGC,aAAa,GAAGpE,OAAAA;AAE7C,IAAA,MAAMqE,YAAe,GAAA;AACnBlE,QAAAA,MAAAA;AACAS,QAAAA,SAAAA;QACA0D,QAAUtD,EAAAA,eAAAA;AACVmD,QAAAA,OAAAA;AACAJ,QAAAA,cAAAA;AACAnE,QAAAA,GAAAA;AACAQ,QAAAA,OAAAA;AACAyC,QAAAA,QAAAA;AACAU,QAAAA,KAAAA;AACAhC,aAAAA,KAAAA;AACA0C,QAAAA,QAAAA;AACApE,QAAAA,MAAAA;QACAG,OAASoE,EAAAA,WAAAA;QACTZ,OAASE,EAAAA,gBAAAA;AACTJ,QAAAA,UAAAA;QACAvD,MAAQE,EAAAA,cAAAA;AACR2D,QAAAA,MAAAA;AACA9D,QAAAA;AACF,KAAA;IAEA,OAAOuE,YAAAA;AACT;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-build-context.mjs","sources":["../../../src/node/create-build-context.ts"],"sourcesContent":["import os from 'node:os';\nimport path from 'node:path';\nimport fs from 'node:fs/promises';\nimport browserslist from 'browserslist';\nimport { createStrapi } from '@strapi/core';\nimport type { Core, Modules } from '@strapi/types';\nimport type { Server } from 'node:http';\n\nimport type { CLIContext } from '../cli/types';\nimport { getStrapiAdminEnvVars, loadEnv } from './core/env';\n\nimport { PluginMeta, getEnabledPlugins, getMapOfPluginsWithAdmin } from './core/plugins';\nimport { AppFile, loadUserAppFile } from './core/admin-customisations';\nimport type { BaseContext } from './types';\n\ninterface BaseOptions {\n stats?: boolean;\n minify?: boolean;\n sourcemaps?: boolean;\n bundler?: 'webpack' | 'vite';\n open?: boolean;\n hmrServer?: Server;\n hmrClientPort?: number;\n}\n\ninterface BuildContext<TOptions = unknown> extends BaseContext {\n /**\n * The customisations defined by the user in their app.js file\n */\n customisations?: AppFile;\n /**\n * Features object with future flags\n */\n features?: Modules.Features.FeaturesService['config'];\n /**\n * The build options\n */\n options: BaseOptions & TOptions;\n /**\n * The plugins to be included in the JS bundle\n * incl. internal plugins, third party plugins & local plugins\n */\n plugins: PluginMeta[];\n}\n\ninterface CreateBuildContextArgs<TOptions = unknown> extends CLIContext {\n strapi?: Core.Strapi;\n options?: TOptions;\n}\n\nconst DEFAULT_BROWSERSLIST = [\n 'last 3 major versions',\n 'Firefox ESR',\n 'last 2 Opera versions',\n 'not dead',\n];\n\nconst createBuildContext = async <TOptions extends BaseOptions>({\n cwd,\n logger,\n tsconfig,\n strapi,\n options = {} as TOptions,\n}: CreateBuildContextArgs<TOptions>): Promise<BuildContext<TOptions>> => {\n /**\n * If you make a new strapi instance when one already exists,\n * you will overwrite the global and the app will _most likely_\n * crash and die.\n */\n const strapiInstance =\n strapi ??\n createStrapi({\n // Directories\n appDir: cwd,\n distDir: tsconfig?.config.options.outDir ?? '',\n // Options\n autoReload: true,\n serveAdminPanel: false,\n });\n\n const serverAbsoluteUrl = strapiInstance.config.get<string>('server.absoluteUrl');\n const adminAbsoluteUrl = strapiInstance.config.get<string>('admin.absoluteUrl');\n const adminPath = strapiInstance.config.get<string>('admin.path');\n\n // NOTE: Checks that both the server and admin will be served from the same origin (protocol, host, port)\n const sameOrigin = new URL(adminAbsoluteUrl).origin === new URL(serverAbsoluteUrl).origin;\n\n const adminPublicPath = new URL(adminAbsoluteUrl).pathname;\n const serverPublicPath = new URL(serverAbsoluteUrl).pathname;\n\n const appDir = strapiInstance.dirs.app.root;\n\n await loadEnv(cwd);\n\n const env = getStrapiAdminEnvVars({\n ADMIN_PATH: adminPublicPath,\n STRAPI_ADMIN_BACKEND_URL: sameOrigin ? serverPublicPath : serverAbsoluteUrl,\n STRAPI_TELEMETRY_DISABLED: String(strapiInstance.telemetry.isDisabled),\n // TODO: Get this url from a utility/consts rather than duplicating it in AIChat constants.ts\n STRAPI_AI_URL:\n process.env.STRAPI_AI_URL?.replace(/\\/+$/, '') ?? 'https://strapi-ai.apps.strapi.io',\n STRAPI_ANALYTICS_URL: process.env.STRAPI_ANALYTICS_URL || 'https://analytics.strapi.io',\n });\n\n const envKeys = Object.keys(env);\n\n if (envKeys.length > 0) {\n logger.info(\n [\n 'Including the following ENV variables as part of the JS bundle:',\n ...envKeys.map((key) => ` - ${key}`),\n ].join(os.EOL)\n );\n }\n\n const distPath = path.join(strapiInstance.dirs.dist.root, 'build');\n const distDir = path.relative(cwd, distPath);\n\n /**\n * If the distPath already exists, clean it\n */\n try {\n logger.debug(`Cleaning dist folder: ${distPath}`);\n await fs.rm(distPath, { recursive: true, force: true });\n logger.debug('Cleaned dist folder');\n } catch {\n // do nothing, it will fail if the folder does not exist\n logger.debug('There was no dist folder to clean');\n }\n\n const runtimeDir = path.join(cwd, '.strapi', 'client');\n const entry = path.relative(cwd, path.join(runtimeDir, 'app.js'));\n\n const plugins = await getEnabledPlugins({ cwd, logger, runtimeDir, strapi: strapiInstance });\n\n logger.debug('Enabled plugins', os.EOL, plugins);\n\n const pluginsWithFront = getMapOfPluginsWithAdmin(plugins);\n\n logger.debug('Enabled plugins with FE', os.EOL, pluginsWithFront);\n\n const target = browserslist.loadConfig({ path: cwd }) ?? DEFAULT_BROWSERSLIST;\n\n const customisations = await loadUserAppFile({ appDir, runtimeDir });\n\n const features = strapiInstance.config.get('features', undefined);\n\n const { bundler = 'vite', ...restOptions } = options;\n\n const buildContext = {\n appDir,\n adminPath,\n basePath: adminPublicPath,\n bundler,\n customisations,\n cwd,\n distDir,\n distPath,\n entry,\n env,\n features,\n logger,\n options: restOptions as BaseOptions & TOptions,\n plugins: pluginsWithFront,\n runtimeDir,\n strapi: strapiInstance,\n target,\n tsconfig,\n } satisfies BuildContext<TOptions>;\n\n return buildContext;\n};\n\nexport { createBuildContext };\nexport type { BuildContext, CreateBuildContextArgs };\n"],"names":["DEFAULT_BROWSERSLIST","createBuildContext","cwd","logger","tsconfig","strapi","options","strapiInstance","createStrapi","appDir","distDir","config","outDir","autoReload","serveAdminPanel","serverAbsoluteUrl","get","adminAbsoluteUrl","adminPath","sameOrigin","URL","origin","adminPublicPath","pathname","serverPublicPath","dirs","app","root","loadEnv","env","getStrapiAdminEnvVars","ADMIN_PATH","STRAPI_ADMIN_BACKEND_URL","STRAPI_TELEMETRY_DISABLED","String","telemetry","isDisabled","STRAPI_AI_URL","process","replace","STRAPI_ANALYTICS_URL","envKeys","Object","keys","length","info","map","key","join","os","EOL","distPath","path","dist","relative","debug","fs","rm","recursive","force","runtimeDir","entry","plugins","getEnabledPlugins","pluginsWithFront","getMapOfPluginsWithAdmin","target","browserslist","loadConfig","customisations","loadUserAppFile","features","undefined","bundler","restOptions","buildContext","basePath"],"mappings":";;;;;;;;;AAkDA,MAAMA,oBAAuB,GAAA;AAC3B,IAAA,uBAAA;AACA,IAAA,aAAA;AACA,IAAA,uBAAA;AACA,IAAA;AACD,CAAA;AAED,MAAMC,kBAAqB,GAAA,OAAqC,EAC9DC,GAAG,EACHC,MAAM,EACNC,QAAQ,EACRC,MAAM,EACNC,OAAU,GAAA,EAAc,EACS,GAAA;AACjC;;;;MAKA,MAAMC,cACJF,GAAAA,MAAAA,IACAG,YAAa,CAAA;;QAEXC,MAAQP,EAAAA,GAAAA;QACRQ,OAASN,EAAAA,QAAAA,EAAUO,MAAOL,CAAAA,OAAAA,CAAQM,MAAU,IAAA,EAAA;;QAE5CC,UAAY,EAAA,IAAA;QACZC,eAAiB,EAAA;AACnB,KAAA,CAAA;AAEF,IAAA,MAAMC,iBAAoBR,GAAAA,cAAAA,CAAeI,MAAM,CAACK,GAAG,CAAS,oBAAA,CAAA;AAC5D,IAAA,MAAMC,gBAAmBV,GAAAA,cAAAA,CAAeI,MAAM,CAACK,GAAG,CAAS,mBAAA,CAAA;AAC3D,IAAA,MAAME,SAAYX,GAAAA,cAAAA,CAAeI,MAAM,CAACK,GAAG,CAAS,YAAA,CAAA;;IAGpD,MAAMG,UAAAA,GAAa,IAAIC,GAAIH,CAAAA,gBAAAA,CAAAA,CAAkBI,MAAM,KAAK,IAAID,GAAIL,CAAAA,iBAAAA,CAAAA,CAAmBM,MAAM;AAEzF,IAAA,MAAMC,eAAkB,GAAA,IAAIF,GAAIH,CAAAA,gBAAAA,CAAAA,CAAkBM,QAAQ;AAC1D,IAAA,MAAMC,gBAAmB,GAAA,IAAIJ,GAAIL,CAAAA,iBAAAA,CAAAA,CAAmBQ,QAAQ;AAE5D,IAAA,MAAMd,SAASF,cAAekB,CAAAA,IAAI,CAACC,GAAG,CAACC,IAAI;AAE3C,IAAA,MAAMC,OAAQ1B,CAAAA,GAAAA,CAAAA;AAEd,IAAA,MAAM2B,MAAMC,qBAAsB,CAAA;QAChCC,UAAYT,EAAAA,eAAAA;AACZU,QAAAA,wBAAAA,EAA0Bb,aAAaK,gBAAmBT,GAAAA,iBAAAA;AAC1DkB,QAAAA,yBAAAA,EAA2BC,MAAO3B,CAAAA,cAAAA,CAAe4B,SAAS,CAACC,UAAU,CAAA;;AAErEC,QAAAA,aAAAA,EACEC,QAAQT,GAAG,CAACQ,aAAa,EAAEE,OAAAA,CAAQ,QAAQ,EAAO,CAAA,IAAA,kCAAA;AACpDC,QAAAA,oBAAAA,EAAsBF,OAAQT,CAAAA,GAAG,CAACW,oBAAoB,IAAI;AAC5D,KAAA,CAAA;IAEA,MAAMC,OAAAA,GAAUC,MAAOC,CAAAA,IAAI,CAACd,GAAAA,CAAAA;IAE5B,IAAIY,OAAAA,CAAQG,MAAM,GAAG,CAAG,EAAA;AACtBzC,QAAAA,MAAAA,CAAO0C,IAAI,CACT;AACE,YAAA,iEAAA;
|
|
1
|
+
{"version":3,"file":"create-build-context.mjs","sources":["../../../src/node/create-build-context.ts"],"sourcesContent":["import os from 'node:os';\nimport path from 'node:path';\nimport fs from 'node:fs/promises';\nimport browserslist from 'browserslist';\nimport { createStrapi } from '@strapi/core';\nimport type { Core, Modules } from '@strapi/types';\nimport type { Server } from 'node:http';\n\nimport type { CLIContext } from '../cli/types';\nimport { getStrapiAdminEnvVars, loadEnv } from './core/env';\n\nimport { PluginMeta, getEnabledPlugins, getMapOfPluginsWithAdmin } from './core/plugins';\nimport { AppFile, loadUserAppFile } from './core/admin-customisations';\nimport type { BaseContext } from './types';\n\ninterface BaseOptions {\n stats?: boolean;\n minify?: boolean;\n sourcemaps?: boolean;\n bundler?: 'webpack' | 'vite';\n open?: boolean;\n hmrServer?: Server;\n hmrClientPort?: number;\n}\n\ninterface BuildContext<TOptions = unknown> extends BaseContext {\n /**\n * The customisations defined by the user in their app.js file\n */\n customisations?: AppFile;\n /**\n * Features object with future flags\n */\n features?: Modules.Features.FeaturesService['config'];\n /**\n * The build options\n */\n options: BaseOptions & TOptions;\n /**\n * The plugins to be included in the JS bundle\n * incl. internal plugins, third party plugins & local plugins\n */\n plugins: PluginMeta[];\n}\n\ninterface CreateBuildContextArgs<TOptions = unknown> extends CLIContext {\n strapi?: Core.Strapi;\n options?: TOptions;\n}\n\nconst DEFAULT_BROWSERSLIST = [\n 'last 3 major versions',\n 'Firefox ESR',\n 'last 2 Opera versions',\n 'not dead',\n];\n\nconst createBuildContext = async <TOptions extends BaseOptions>({\n cwd,\n logger,\n tsconfig,\n strapi,\n options = {} as TOptions,\n}: CreateBuildContextArgs<TOptions>): Promise<BuildContext<TOptions>> => {\n /**\n * If you make a new strapi instance when one already exists,\n * you will overwrite the global and the app will _most likely_\n * crash and die.\n */\n const strapiInstance =\n strapi ??\n createStrapi({\n // Directories\n appDir: cwd,\n distDir: tsconfig?.config.options.outDir ?? '',\n // Options\n autoReload: true,\n serveAdminPanel: false,\n });\n\n const serverAbsoluteUrl = strapiInstance.config.get<string>('server.absoluteUrl');\n const adminAbsoluteUrl = strapiInstance.config.get<string>('admin.absoluteUrl');\n const adminPath = strapiInstance.config.get<string>('admin.path');\n\n // NOTE: Checks that both the server and admin will be served from the same origin (protocol, host, port)\n const sameOrigin = new URL(adminAbsoluteUrl).origin === new URL(serverAbsoluteUrl).origin;\n\n const adminPublicPath = new URL(adminAbsoluteUrl).pathname;\n const serverPublicPath = new URL(serverAbsoluteUrl).pathname;\n\n const appDir = strapiInstance.dirs.app.root;\n\n await loadEnv(cwd);\n\n const env = getStrapiAdminEnvVars({\n ADMIN_PATH: adminPublicPath,\n STRAPI_ADMIN_BACKEND_URL: sameOrigin ? serverPublicPath : serverAbsoluteUrl,\n STRAPI_TELEMETRY_DISABLED: String(strapiInstance.telemetry.isDisabled),\n // TODO: Get this url from a utility/consts rather than duplicating it in AIChat constants.ts\n STRAPI_AI_URL:\n process.env.STRAPI_AI_URL?.replace(/\\/+$/, '') ?? 'https://strapi-ai.apps.strapi.io',\n STRAPI_ANALYTICS_URL: process.env.STRAPI_ANALYTICS_URL || 'https://analytics.strapi.io',\n });\n\n const envKeys = Object.keys(env);\n\n if (envKeys.length > 0) {\n logger.info(\n [\n 'Including the following ENV variables as part of the JS bundle:',\n ...envKeys.map((key) => ` - ${key}`),\n ].join(os.EOL)\n );\n }\n\n const distPath = path.join(strapiInstance.dirs.dist.root, 'build');\n const distDir = path.relative(cwd, distPath);\n\n /**\n * If the distPath already exists, clean it\n */\n try {\n logger.debug(`Cleaning dist folder: ${distPath}`);\n await fs.rm(distPath, { recursive: true, force: true });\n logger.debug('Cleaned dist folder');\n } catch {\n // do nothing, it will fail if the folder does not exist\n logger.debug('There was no dist folder to clean');\n }\n\n const runtimeDir = path.join(cwd, '.strapi', 'client');\n const entry = path.relative(cwd, path.join(runtimeDir, 'app.js'));\n\n const plugins = await getEnabledPlugins({ cwd, logger, runtimeDir, strapi: strapiInstance });\n\n logger.debug('Enabled plugins', os.EOL, plugins);\n\n const pluginsWithFront = getMapOfPluginsWithAdmin(plugins);\n\n logger.debug('Enabled plugins with FE', os.EOL, pluginsWithFront);\n\n const target = browserslist.loadConfig({ path: cwd }) ?? DEFAULT_BROWSERSLIST;\n\n const customisations = await loadUserAppFile({ appDir, runtimeDir });\n\n const features = strapiInstance.config.get('features', undefined);\n\n const { bundler = 'vite', ...restOptions } = options;\n\n const buildContext = {\n appDir,\n adminPath,\n basePath: adminPublicPath,\n bundler,\n customisations,\n cwd,\n distDir,\n distPath,\n entry,\n env,\n features,\n logger,\n options: restOptions as BaseOptions & TOptions,\n plugins: pluginsWithFront,\n runtimeDir,\n strapi: strapiInstance,\n target,\n tsconfig,\n } satisfies BuildContext<TOptions>;\n\n return buildContext;\n};\n\nexport { createBuildContext };\nexport type { BuildContext, CreateBuildContextArgs };\n"],"names":["DEFAULT_BROWSERSLIST","createBuildContext","cwd","logger","tsconfig","strapi","options","strapiInstance","createStrapi","appDir","distDir","config","outDir","autoReload","serveAdminPanel","serverAbsoluteUrl","get","adminAbsoluteUrl","adminPath","sameOrigin","URL","origin","adminPublicPath","pathname","serverPublicPath","dirs","app","root","loadEnv","env","getStrapiAdminEnvVars","ADMIN_PATH","STRAPI_ADMIN_BACKEND_URL","STRAPI_TELEMETRY_DISABLED","String","telemetry","isDisabled","STRAPI_AI_URL","process","replace","STRAPI_ANALYTICS_URL","envKeys","Object","keys","length","info","map","key","join","os","EOL","distPath","path","dist","relative","debug","fs","rm","recursive","force","runtimeDir","entry","plugins","getEnabledPlugins","pluginsWithFront","getMapOfPluginsWithAdmin","target","browserslist","loadConfig","customisations","loadUserAppFile","features","undefined","bundler","restOptions","buildContext","basePath"],"mappings":";;;;;;;;;AAkDA,MAAMA,oBAAuB,GAAA;AAC3B,IAAA,uBAAA;AACA,IAAA,aAAA;AACA,IAAA,uBAAA;AACA,IAAA;AACD,CAAA;AAED,MAAMC,kBAAqB,GAAA,OAAqC,EAC9DC,GAAG,EACHC,MAAM,EACNC,QAAQ,EACRC,MAAM,EACNC,OAAU,GAAA,EAAc,EACS,GAAA;AACjC;;;;MAKA,MAAMC,cACJF,GAAAA,MAAAA,IACAG,YAAa,CAAA;;QAEXC,MAAQP,EAAAA,GAAAA;QACRQ,OAASN,EAAAA,QAAAA,EAAUO,MAAOL,CAAAA,OAAAA,CAAQM,MAAU,IAA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["../../../src/node/develop.ts"],"sourcesContent":["import * as tsUtils from '@strapi/typescript-utils';\nimport { strings } from '@strapi/utils';\nimport chokidar from 'chokidar';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport cluster from 'node:cluster';\nimport { createStrapi } from '@strapi/core';\n\nimport type { CLIContext } from '../cli/types';\nimport { checkRequiredDependencies } from './core/dependencies';\nimport { getTimer, prettyTime, type TimeMeasurer } from './core/timer';\nimport { createBuildContext } from './create-build-context';\nimport type { WebpackWatcher } from './webpack/watch';\nimport type { ViteWatcher } from './vite/watch';\n\nimport { writeStaticClientFiles } from './staticFiles';\n\ninterface DevelopOptions extends CLIContext {\n /**\n * Which bundler to use for building.\n *\n * @default webpack\n */\n bundler?: 'webpack' | 'vite';\n polling?: boolean;\n open?: boolean;\n watchAdmin?: boolean;\n}\n\n// This method removes all non-admin build files from the dist directory\nconst cleanupDistDirectory = async ({\n tsconfig,\n logger,\n timer,\n}: Pick<DevelopOptions, 'tsconfig' | 'logger'> & { timer: TimeMeasurer }) => {\n const distDir = tsconfig?.config?.options?.outDir;\n\n if (\n !distDir || // we don't have a dist dir\n (await fs\n .access(distDir)\n .then(() => false)\n .catch(() => true)) // it doesn't exist -- if it does but no access, that will be caught later\n ) {\n return;\n }\n\n const timerName = `cleaningDist${Date.now()}`;\n timer.start(timerName);\n const cleaningSpinner = logger.spinner(`Cleaning dist dir ${distDir}`).start();\n\n try {\n const dirContent = await fs.readdir(distDir);\n const validFilenames = dirContent\n // Ignore the admin build folder\n .filter((filename) => filename !== 'build');\n for (const filename of validFilenames) {\n await fs.rm(path.resolve(distDir, filename), { recursive: true });\n }\n } catch (err: unknown) {\n const generatingDuration = timer.end(timerName);\n cleaningSpinner.text = `Error cleaning dist dir: ${err} (${prettyTime(generatingDuration)})`;\n cleaningSpinner?.fail();\n return;\n }\n\n const generatingDuration = timer.end(timerName);\n cleaningSpinner.text = `Cleaning dist dir (${prettyTime(generatingDuration)})`;\n cleaningSpinner?.succeed();\n};\n\nconst develop = async ({\n cwd,\n polling,\n logger,\n tsconfig,\n watchAdmin,\n ...options\n}: DevelopOptions) => {\n const timer = getTimer();\n\n if (cluster.isPrimary) {\n const { didInstall } = await checkRequiredDependencies({ cwd, logger }).catch((err) => {\n logger.error(err.message);\n process.exit(1);\n });\n\n if (didInstall) {\n return;\n }\n\n if (tsconfig?.config) {\n // Build without diagnostics in case schemas have changed\n await cleanupDistDirectory({ tsconfig, logger, timer });\n await tsUtils.compile(cwd, { configOptions: { ignoreDiagnostics: true } });\n }\n\n /**\n * IF we're not watching the admin we're going to build it, this makes\n * sure that at least the admin is built for users & they can interact\n * with the application.\n */\n if (!watchAdmin) {\n timer.start('createBuildContext');\n const contextSpinner = logger.spinner(`Building build context`).start();\n console.log('');\n\n const ctx = await createBuildContext({\n cwd,\n logger,\n tsconfig,\n options,\n });\n const contextDuration = timer.end('createBuildContext');\n contextSpinner.text = `Building build context (${prettyTime(contextDuration)})`;\n contextSpinner.succeed();\n\n timer.start('creatingAdmin');\n const adminSpinner = logger.spinner(`Creating admin`).start();\n\n await writeStaticClientFiles(ctx);\n\n if (ctx.bundler === 'webpack') {\n const { build: buildWebpack } = await import('./webpack/build');\n await buildWebpack(ctx);\n } else if (ctx.bundler === 'vite') {\n const { build: buildVite } = await import('./vite/build');\n await buildVite(ctx);\n }\n\n const adminDuration = timer.end('creatingAdmin');\n adminSpinner.text = `Creating admin (${prettyTime(adminDuration)})`;\n adminSpinner.succeed();\n }\n\n cluster.on('message', async (worker, message) => {\n switch (message) {\n case 'reload': {\n if (tsconfig?.config) {\n // Build without diagnostics in case schemas have changed\n await cleanupDistDirectory({ tsconfig, logger, timer });\n await tsUtils.compile(cwd, { configOptions: { ignoreDiagnostics: true } });\n }\n logger.debug('cluster has the reload message, sending the worker kill message');\n worker.send('kill');\n break;\n }\n case 'killed': {\n logger.debug('cluster has the killed message, forking the cluster');\n cluster.fork();\n break;\n }\n case 'stop': {\n process.exit(1);\n break;\n }\n default:\n break;\n }\n });\n\n cluster.fork();\n }\n\n if (cluster.isWorker) {\n timer.start('loadStrapi');\n const loadStrapiSpinner = logger.spinner(`Loading Strapi`).start();\n\n const strapi = createStrapi({\n appDir: cwd,\n distDir: tsconfig?.config.options.outDir ?? '',\n autoReload: true,\n serveAdminPanel: !watchAdmin,\n });\n\n /**\n * If we're watching the admin panel then we're going to attach the watcher\n * as a strapi middleware.\n */\n let bundleWatcher: WebpackWatcher | ViteWatcher | undefined;\n\n const strapiInstance = await strapi.load();\n\n if (watchAdmin) {\n timer.start('createBuildContext');\n const contextSpinner = logger.spinner(`Building build context`).start();\n console.log('');\n\n const ctx = await createBuildContext({\n cwd,\n logger,\n strapi,\n tsconfig,\n options,\n });\n const contextDuration = timer.end('createBuildContext');\n contextSpinner.text = `Building build context (${prettyTime(contextDuration)})`;\n contextSpinner.succeed();\n\n timer.start('creatingAdmin');\n const adminSpinner = logger.spinner(`Creating admin`).start();\n\n await writeStaticClientFiles(ctx);\n\n if (ctx.bundler === 'webpack') {\n const { watch: watchWebpack } = await import('./webpack/watch');\n bundleWatcher = await watchWebpack(ctx);\n } else if (ctx.bundler === 'vite') {\n const { watch: watchVite } = await import('./vite/watch');\n bundleWatcher = await watchVite(ctx);\n }\n\n const adminDuration = timer.end('creatingAdmin');\n adminSpinner.text = `Creating admin (${prettyTime(adminDuration)})`;\n adminSpinner.succeed();\n }\n\n const loadStrapiDuration = timer.end('loadStrapi');\n loadStrapiSpinner.text = `Loading Strapi (${prettyTime(loadStrapiDuration)})`;\n loadStrapiSpinner.succeed();\n\n // For TS projects, type generation is a requirement for the develop command so that the server can restart\n // For JS projects, we respect the experimental autogenerate setting\n if (tsconfig?.config || strapi.config.get('typescript.autogenerate') !== false) {\n timer.start('generatingTS');\n const generatingTsSpinner = logger.spinner(`Generating types`).start();\n\n await tsUtils.generators.generate({\n strapi: strapiInstance,\n pwd: cwd,\n rootDir: undefined,\n logger: { silent: true, debug: false },\n artifacts: { contentTypes: true, components: true },\n });\n\n const generatingDuration = timer.end('generatingTS');\n generatingTsSpinner.text = `Generating types (${prettyTime(generatingDuration)})`;\n generatingTsSpinner.succeed();\n }\n\n if (tsconfig?.config) {\n timer.start('compilingTS');\n const compilingTsSpinner = logger.spinner(`Compiling TS`).start();\n\n await cleanupDistDirectory({ tsconfig, logger, timer });\n await tsUtils.compile(cwd, { configOptions: { ignoreDiagnostics: false } });\n\n const compilingDuration = timer.end('compilingTS');\n compilingTsSpinner.text = `Compiling TS (${prettyTime(compilingDuration)})`;\n compilingTsSpinner.succeed();\n }\n\n const restart = async () => {\n if (strapiInstance.reload.isWatching && !strapiInstance.reload.isReloading) {\n strapiInstance.reload.isReloading = true;\n strapiInstance.reload();\n }\n };\n\n const watcher = chokidar\n .watch(cwd, {\n ignoreInitial: true,\n usePolling: polling,\n ignored: [\n /(^|[/\\\\])\\../, // dot files\n /tmp/,\n '**/src/admin/**',\n '**/src/plugins/**/admin/**',\n '**/dist/src/plugins/test/admin/**',\n '**/documentation',\n '**/documentation/**',\n '**/node_modules',\n '**/node_modules/**',\n '**/plugins.json',\n '**/build',\n '**/build/**',\n '**/log',\n '**/log/**',\n '**/logs',\n '**/logs/**',\n '**/*.log',\n '**/index.html',\n '**/public',\n '**/public/**',\n strapiInstance.dirs.static.public,\n strings.joinBy('/', strapiInstance.dirs.static.public, '**'),\n '**/*.db*',\n '**/exports/**',\n '**/dist/**',\n '**/*.d.ts',\n '**/.yalc/**',\n '**/yalc.lock',\n // TODO v6: watch only src folder by default, and flip this to watchIncludeFiles\n ...strapiInstance.config.get('admin.watchIgnoreFiles', []),\n ],\n })\n .on('add', (path) => {\n strapiInstance.log.info(`File created: ${path}`);\n restart();\n })\n .on('change', (path) => {\n strapiInstance.log.info(`File changed: ${path}`);\n restart();\n })\n .on('unlink', (path) => {\n strapiInstance.log.info(`File deleted: ${path}`);\n restart();\n });\n\n process.on('message', async (message) => {\n switch (message) {\n case 'kill': {\n logger.debug(\n 'child process has the kill message, destroying the strapi instance and sending the killed process message'\n );\n await watcher.close();\n\n await strapiInstance.destroy();\n\n if (bundleWatcher) {\n bundleWatcher.close();\n }\n process.send?.('killed');\n break;\n }\n default:\n break;\n }\n });\n\n strapiInstance.start();\n }\n};\n\nexport { develop };\nexport type { DevelopOptions };\n"],"names":["cleanupDistDirectory","tsconfig","logger","timer","distDir","config","options","outDir","fs","access","then","catch","timerName","Date","now","start","cleaningSpinner","spinner","dirContent","readdir","validFilenames","filter","filename","rm","path","resolve","recursive","err","generatingDuration","end","text","prettyTime","fail","succeed","develop","cwd","polling","watchAdmin","getTimer","cluster","isPrimary","didInstall","checkRequiredDependencies","error","message","process","exit","tsUtils","compile","configOptions","ignoreDiagnostics","contextSpinner","console","log","ctx","createBuildContext","contextDuration","adminSpinner","writeStaticClientFiles","bundler","build","buildWebpack","buildVite","adminDuration","on","worker","debug","send","fork","isWorker","loadStrapiSpinner","strapi","createStrapi","appDir","autoReload","serveAdminPanel","bundleWatcher","strapiInstance","load","watch","watchWebpack","watchVite","loadStrapiDuration","get","generatingTsSpinner","generators","generate","pwd","rootDir","undefined","silent","artifacts","contentTypes","components","compilingTsSpinner","compilingDuration","restart","reload","isWatching","isReloading","watcher","chokidar","ignoreInitial","usePolling","ignored","dirs","static","public","strings","joinBy","info","close","destroy"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA;AACA,MAAMA,oBAAAA,GAAuB,OAAO,EAClCC,QAAQ,EACRC,MAAM,SACNC,OAAK,EACiE,GAAA;IACtE,MAAMC,OAAAA,GAAUH,QAAUI,EAAAA,MAAAA,EAAQC,OAASC,EAAAA,MAAAA;IAE3C,IACE,CAACH;AACA,IAAA,MAAMI,EACJC,CAAAA,MAAM,CAACL,OAAAA,CAAAA,CACPM,IAAI,CAAC,IAAM,KAAA,CAAA,CACXC,KAAK,CAAC,IAAM,IAAA,CAAA;AACf,MAAA;AACA,QAAA;AACF;AAEA,IAAA,MAAMC,YAAY,CAAC,YAAY,EAAEC,IAAKC,CAAAA,GAAG,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AAQW,KAAK,EAAA;AAEnB,wBAAA,MAAMlC,eAAemC,OAAO,EAAA;AAE5B,wBAAA,IAAIpC,aAAe,EAAA;AACjBA,4BAAAA,aAAAA,CAAcmC,KAAK,EAAA;AACrB;AACAlE,wBAAAA,OAAAA,CAAQsB,IAAI,GAAG,QAAA,CAAA;AACf,wBAAA;AACF;AAGF;AACF,SAAA,CAAA;AAEAU,QAAAA,cAAAA,CAAe9D,KAAK,EAAA;AACtB;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"develop.js","sources":["../../../src/node/develop.ts"],"sourcesContent":["import * as tsUtils from '@strapi/typescript-utils';\nimport { strings } from '@strapi/utils';\nimport chokidar from 'chokidar';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport cluster from 'node:cluster';\nimport { createStrapi } from '@strapi/core';\n\nimport type { CLIContext } from '../cli/types';\nimport { checkRequiredDependencies } from './core/dependencies';\nimport { getTimer, prettyTime, type TimeMeasurer } from './core/timer';\nimport { createBuildContext } from './create-build-context';\nimport type { WebpackWatcher } from './webpack/watch';\nimport type { ViteWatcher } from './vite/watch';\n\nimport { writeStaticClientFiles } from './staticFiles';\n\ninterface DevelopOptions extends CLIContext {\n /**\n * Which bundler to use for building.\n *\n * @default webpack\n */\n bundler?: 'webpack' | 'vite';\n polling?: boolean;\n open?: boolean;\n watchAdmin?: boolean;\n}\n\n// This method removes all non-admin build files from the dist directory\nconst cleanupDistDirectory = async ({\n tsconfig,\n logger,\n timer,\n}: Pick<DevelopOptions, 'tsconfig' | 'logger'> & { timer: TimeMeasurer }) => {\n const distDir = tsconfig?.config?.options?.outDir;\n\n if (\n !distDir || // we don't have a dist dir\n (await fs\n .access(distDir)\n .then(() => false)\n .catch(() => true)) // it doesn't exist -- if it does but no access, that will be caught later\n ) {\n return;\n }\n\n const timerName = `cleaningDist${Date.now()}`;\n timer.start(timerName);\n const cleaningSpinner = logger.spinner(`Cleaning dist dir ${distDir}`).start();\n\n try {\n const dirContent = await fs.readdir(distDir);\n const validFilenames = dirContent\n // Ignore the admin build folder\n .filter((filename) => filename !== 'build');\n for (const filename of validFilenames) {\n await fs.rm(path.resolve(distDir, filename), { recursive: true });\n }\n } catch (err: unknown) {\n const generatingDuration = timer.end(timerName);\n cleaningSpinner.text = `Error cleaning dist dir: ${err} (${prettyTime(generatingDuration)})`;\n cleaningSpinner?.fail();\n return;\n }\n\n const generatingDuration = timer.end(timerName);\n cleaningSpinner.text = `Cleaning dist dir (${prettyTime(generatingDuration)})`;\n cleaningSpinner?.succeed();\n};\n\nconst develop = async ({\n cwd,\n polling,\n logger,\n tsconfig,\n watchAdmin,\n ...options\n}: DevelopOptions) => {\n const timer = getTimer();\n\n if (cluster.isPrimary) {\n const { didInstall } = await checkRequiredDependencies({ cwd, logger }).catch((err) => {\n logger.error(err.message);\n process.exit(1);\n });\n\n if (didInstall) {\n return;\n }\n\n if (tsconfig?.config) {\n // Build without diagnostics in case schemas have changed\n await cleanupDistDirectory({ tsconfig, logger, timer });\n await tsUtils.compile(cwd, { configOptions: { ignoreDiagnostics: true } });\n }\n\n /**\n * IF we're not watching the admin we're going to build it, this makes\n * sure that at least the admin is built for users & they can interact\n * with the application.\n */\n if (!watchAdmin) {\n timer.start('createBuildContext');\n const contextSpinner = logger.spinner(`Building build context`).start();\n console.log('');\n\n const ctx = await createBuildContext({\n cwd,\n logger,\n tsconfig,\n options,\n });\n const contextDuration = timer.end('createBuildContext');\n contextSpinner.text = `Building build context (${prettyTime(contextDuration)})`;\n contextSpinner.succeed();\n\n timer.start('creatingAdmin');\n const adminSpinner = logger.spinner(`Creating admin`).start();\n\n await writeStaticClientFiles(ctx);\n\n if (ctx.bundler === 'webpack') {\n const { build: buildWebpack } = await import('./webpack/build');\n await buildWebpack(ctx);\n } else if (ctx.bundler === 'vite') {\n const { build: buildVite } = await import('./vite/build');\n await buildVite(ctx);\n }\n\n const adminDuration = timer.end('creatingAdmin');\n adminSpinner.text = `Creating admin (${prettyTime(adminDuration)})`;\n adminSpinner.succeed();\n }\n\n cluster.on('message', async (worker, message) => {\n switch (message) {\n case 'reload': {\n if (tsconfig?.config) {\n // Build without diagnostics in case schemas have changed\n await cleanupDistDirectory({ tsconfig, logger, timer });\n await tsUtils.compile(cwd, { configOptions: { ignoreDiagnostics: true } });\n }\n logger.debug('cluster has the reload message, sending the worker kill message');\n worker.send('kill');\n break;\n }\n case 'killed': {\n logger.debug('cluster has the killed message, forking the cluster');\n cluster.fork();\n break;\n }\n case 'stop': {\n process.exit(1);\n break;\n }\n default:\n break;\n }\n });\n\n cluster.fork();\n }\n\n if (cluster.isWorker) {\n timer.start('loadStrapi');\n const loadStrapiSpinner = logger.spinner(`Loading Strapi`).start();\n\n const strapi = createStrapi({\n appDir: cwd,\n distDir: tsconfig?.config.options.outDir ?? '',\n autoReload: true,\n serveAdminPanel: !watchAdmin,\n });\n\n /**\n * If we're watching the admin panel then we're going to attach the watcher\n * as a strapi middleware.\n */\n let bundleWatcher: WebpackWatcher | ViteWatcher | undefined;\n\n const strapiInstance = await strapi.load();\n\n if (watchAdmin) {\n timer.start('createBuildContext');\n const contextSpinner = logger.spinner(`Building build context`).start();\n console.log('');\n\n const ctx = await createBuildContext({\n cwd,\n logger,\n strapi,\n tsconfig,\n options,\n });\n const contextDuration = timer.end('createBuildContext');\n contextSpinner.text = `Building build context (${prettyTime(contextDuration)})`;\n contextSpinner.succeed();\n\n timer.start('creatingAdmin');\n const adminSpinner = logger.spinner(`Creating admin`).start();\n\n await writeStaticClientFiles(ctx);\n\n if (ctx.bundler === 'webpack') {\n const { watch: watchWebpack } = await import('./webpack/watch');\n bundleWatcher = await watchWebpack(ctx);\n } else if (ctx.bundler === 'vite') {\n const { watch: watchVite } = await import('./vite/watch');\n bundleWatcher = await watchVite(ctx);\n }\n\n const adminDuration = timer.end('creatingAdmin');\n adminSpinner.text = `Creating admin (${prettyTime(adminDuration)})`;\n adminSpinner.succeed();\n }\n\n const loadStrapiDuration = timer.end('loadStrapi');\n loadStrapiSpinner.text = `Loading Strapi (${prettyTime(loadStrapiDuration)})`;\n loadStrapiSpinner.succeed();\n\n // For TS projects, type generation is a requirement for the develop command so that the server can restart\n // For JS projects, we respect the experimental autogenerate setting\n if (tsconfig?.config || strapi.config.get('typescript.autogenerate') !== false) {\n timer.start('generatingTS');\n const generatingTsSpinner = logger.spinner(`Generating types`).start();\n\n await tsUtils.generators.generate({\n strapi: strapiInstance,\n pwd: cwd,\n rootDir: undefined,\n logger: { silent: true, debug: false },\n artifacts: { contentTypes: true, components: true },\n });\n\n const generatingDuration = timer.end('generatingTS');\n generatingTsSpinner.text = `Generating types (${prettyTime(generatingDuration)})`;\n generatingTsSpinner.succeed();\n }\n\n if (tsconfig?.config) {\n timer.start('compilingTS');\n const compilingTsSpinner = logger.spinner(`Compiling TS`).start();\n\n await cleanupDistDirectory({ tsconfig, logger, timer });\n await tsUtils.compile(cwd, { configOptions: { ignoreDiagnostics: false } });\n\n const compilingDuration = timer.end('compilingTS');\n compilingTsSpinner.text = `Compiling TS (${prettyTime(compilingDuration)})`;\n compilingTsSpinner.succeed();\n }\n\n const restart = async () => {\n if (strapiInstance.reload.isWatching && !strapiInstance.reload.isReloading) {\n strapiInstance.reload.isReloading = true;\n strapiInstance.reload();\n }\n };\n\n const watcher = chokidar\n .watch(cwd, {\n ignoreInitial: true,\n usePolling: polling,\n ignored: [\n /(^|[/\\\\])\\../, // dot files\n /tmp/,\n '**/src/admin/**',\n '**/src/plugins/**/admin/**',\n '**/dist/src/plugins/test/admin/**',\n '**/documentation',\n '**/documentation/**',\n '**/node_modules',\n '**/node_modules/**',\n '**/plugins.json',\n '**/build',\n '**/build/**',\n '**/log',\n '**/log/**',\n '**/logs',\n '**/logs/**',\n '**/*.log',\n '**/index.html',\n '**/public',\n '**/public/**',\n strapiInstance.dirs.static.public,\n strings.joinBy('/', strapiInstance.dirs.static.public, '**'),\n '**/*.db*',\n '**/exports/**',\n '**/dist/**',\n '**/*.d.ts',\n '**/.yalc/**',\n '**/yalc.lock',\n // TODO v6: watch only src folder by default, and flip this to watchIncludeFiles\n ...strapiInstance.config.get('admin.watchIgnoreFiles', []),\n ],\n })\n .on('add', (path) => {\n strapiInstance.log.info(`File created: ${path}`);\n restart();\n })\n .on('change', (path) => {\n strapiInstance.log.info(`File changed: ${path}`);\n restart();\n })\n .on('unlink', (path) => {\n strapiInstance.log.info(`File deleted: ${path}`);\n restart();\n });\n\n process.on('message', async (message) => {\n switch (message) {\n case 'kill': {\n logger.debug(\n 'child process has the kill message, destroying the strapi instance and sending the killed process message'\n );\n await watcher.close();\n\n await strapiInstance.destroy();\n\n if (bundleWatcher) {\n bundleWatcher.close();\n }\n process.send?.('killed');\n break;\n }\n default:\n break;\n }\n });\n\n strapiInstance.start();\n }\n};\n\nexport { develop };\nexport type { DevelopOptions };\n"],"names":["cleanupDistDirectory","tsconfig","logger","timer","distDir","config","options","outDir","fs","access","then","catch","timerName","Date","now","start","cleaningSpinner","spinner","dirContent","readdir","validFilenames","filter","filename","rm","path","resolve","recursive","err","generatingDuration","end","text","prettyTime","fail","succeed","develop","cwd","polling","watchAdmin","getTimer","cluster","isPrimary","didInstall","checkRequiredDependencies","error","message","process","exit","tsUtils","compile","configOptions","ignoreDiagnostics","contextSpinner","console","log","ctx","createBuildContext","contextDuration","adminSpinner","writeStaticClientFiles","bundler","build","buildWebpack","buildVite","adminDuration","on","worker","debug","send","fork","isWorker","loadStrapiSpinner","strapi","createStrapi","appDir","autoReload","serveAdminPanel","bundleWatcher","strapiInstance","load","watch","watchWebpack","watchVite","loadStrapiDuration","get","generatingTsSpinner","generators","generate","pwd","rootDir","undefined","silent","artifacts","contentTypes","components","compilingTsSpinner","compilingDuration","restart","reload","isWatching","isReloading","watcher","chokidar","ignoreInitial","usePolling","ignored","dirs","static","public","strings","joinBy","info","close","destroy"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA;AACA,MAAMA,oBAAAA,GAAuB,OAAO,EAClCC,QAAQ,EACRC,MAAM,SACNC,O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ACxC,IAAAA,GAAAA;AACbqD,YAAAA,cAAAA,CAAexB,GAAG,CAACyD,IAAI,CAAC,CAAC,cAAc,EAAEtF,IAAM,CAAA,CAAA,CAAA;AAC/CwE,YAAAA,OAAAA,EAAAA;AACF,SAAA,CAAA;QAEFnD,OAAQmB,CAAAA,EAAE,CAAC,SAAA,EAAW,OAAOpB,OAAAA,GAAAA;YAC3B,OAAQA,OAAAA;gBACN,KAAK,MAAA;AAAQ,oBAAA;AACX1C,wBAAAA,MAAAA,CAAOgE,KAAK,CACV,2GAAA,CAAA;AAEF,wBAAA,MAAMkC,QAAQW,KAAK,EAAA;AAEnB,wBAAA,MAAMlC,eAAemC,OAAO,EAAA;AAE5B,wBAAA,IAAIpC,aAAe,EAAA;AACjBA,4BAAAA,aAAAA,CAAcmC,KAAK,EAAA;AACrB;AACAlE,wBAAAA,OAAAA,CAAQsB,IAAI,GAAG,QAAA,CAAA;AACf,wBAAA;AACF;AAGF;AACF,SAAA,CAAA;AAEAU,QAAAA,cAAAA,CAAe9D,KAAK,EAAA;AACtB;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"develop.mjs","sources":["../../../src/node/develop.ts"],"sourcesContent":["import * as tsUtils from '@strapi/typescript-utils';\nimport { strings } from '@strapi/utils';\nimport chokidar from 'chokidar';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport cluster from 'node:cluster';\nimport { createStrapi } from '@strapi/core';\n\nimport type { CLIContext } from '../cli/types';\nimport { checkRequiredDependencies } from './core/dependencies';\nimport { getTimer, prettyTime, type TimeMeasurer } from './core/timer';\nimport { createBuildContext } from './create-build-context';\nimport type { WebpackWatcher } from './webpack/watch';\nimport type { ViteWatcher } from './vite/watch';\n\nimport { writeStaticClientFiles } from './staticFiles';\n\ninterface DevelopOptions extends CLIContext {\n /**\n * Which bundler to use for building.\n *\n * @default webpack\n */\n bundler?: 'webpack' | 'vite';\n polling?: boolean;\n open?: boolean;\n watchAdmin?: boolean;\n}\n\n// This method removes all non-admin build files from the dist directory\nconst cleanupDistDirectory = async ({\n tsconfig,\n logger,\n timer,\n}: Pick<DevelopOptions, 'tsconfig' | 'logger'> & { timer: TimeMeasurer }) => {\n const distDir = tsconfig?.config?.options?.outDir;\n\n if (\n !distDir || // we don't have a dist dir\n (await fs\n .access(distDir)\n .then(() => false)\n .catch(() => true)) // it doesn't exist -- if it does but no access, that will be caught later\n ) {\n return;\n }\n\n const timerName = `cleaningDist${Date.now()}`;\n timer.start(timerName);\n const cleaningSpinner = logger.spinner(`Cleaning dist dir ${distDir}`).start();\n\n try {\n const dirContent = await fs.readdir(distDir);\n const validFilenames = dirContent\n // Ignore the admin build folder\n .filter((filename) => filename !== 'build');\n for (const filename of validFilenames) {\n await fs.rm(path.resolve(distDir, filename), { recursive: true });\n }\n } catch (err: unknown) {\n const generatingDuration = timer.end(timerName);\n cleaningSpinner.text = `Error cleaning dist dir: ${err} (${prettyTime(generatingDuration)})`;\n cleaningSpinner?.fail();\n return;\n }\n\n const generatingDuration = timer.end(timerName);\n cleaningSpinner.text = `Cleaning dist dir (${prettyTime(generatingDuration)})`;\n cleaningSpinner?.succeed();\n};\n\nconst develop = async ({\n cwd,\n polling,\n logger,\n tsconfig,\n watchAdmin,\n ...options\n}: DevelopOptions) => {\n const timer = getTimer();\n\n if (cluster.isPrimary) {\n const { didInstall } = await checkRequiredDependencies({ cwd, logger }).catch((err) => {\n logger.error(err.message);\n process.exit(1);\n });\n\n if (didInstall) {\n return;\n }\n\n if (tsconfig?.config) {\n // Build without diagnostics in case schemas have changed\n await cleanupDistDirectory({ tsconfig, logger, timer });\n await tsUtils.compile(cwd, { configOptions: { ignoreDiagnostics: true } });\n }\n\n /**\n * IF we're not watching the admin we're going to build it, this makes\n * sure that at least the admin is built for users & they can interact\n * with the application.\n */\n if (!watchAdmin) {\n timer.start('createBuildContext');\n const contextSpinner = logger.spinner(`Building build context`).start();\n console.log('');\n\n const ctx = await createBuildContext({\n cwd,\n logger,\n tsconfig,\n options,\n });\n const contextDuration = timer.end('createBuildContext');\n contextSpinner.text = `Building build context (${prettyTime(contextDuration)})`;\n contextSpinner.succeed();\n\n timer.start('creatingAdmin');\n const adminSpinner = logger.spinner(`Creating admin`).start();\n\n await writeStaticClientFiles(ctx);\n\n if (ctx.bundler === 'webpack') {\n const { build: buildWebpack } = await import('./webpack/build');\n await buildWebpack(ctx);\n } else if (ctx.bundler === 'vite') {\n const { build: buildVite } = await import('./vite/build');\n await buildVite(ctx);\n }\n\n const adminDuration = timer.end('creatingAdmin');\n adminSpinner.text = `Creating admin (${prettyTime(adminDuration)})`;\n adminSpinner.succeed();\n }\n\n cluster.on('message', async (worker, message) => {\n switch (message) {\n case 'reload': {\n if (tsconfig?.config) {\n // Build without diagnostics in case schemas have changed\n await cleanupDistDirectory({ tsconfig, logger, timer });\n await tsUtils.compile(cwd, { configOptions: { ignoreDiagnostics: true } });\n }\n logger.debug('cluster has the reload message, sending the worker kill message');\n worker.send('kill');\n break;\n }\n case 'killed': {\n logger.debug('cluster has the killed message, forking the cluster');\n cluster.fork();\n break;\n }\n case 'stop': {\n process.exit(1);\n break;\n }\n default:\n break;\n }\n });\n\n cluster.fork();\n }\n\n if (cluster.isWorker) {\n timer.start('loadStrapi');\n const loadStrapiSpinner = logger.spinner(`Loading Strapi`).start();\n\n const strapi = createStrapi({\n appDir: cwd,\n distDir: tsconfig?.config.options.outDir ?? '',\n autoReload: true,\n serveAdminPanel: !watchAdmin,\n });\n\n /**\n * If we're watching the admin panel then we're going to attach the watcher\n * as a strapi middleware.\n */\n let bundleWatcher: WebpackWatcher | ViteWatcher | undefined;\n\n const strapiInstance = await strapi.load();\n\n if (watchAdmin) {\n timer.start('createBuildContext');\n const contextSpinner = logger.spinner(`Building build context`).start();\n console.log('');\n\n const ctx = await createBuildContext({\n cwd,\n logger,\n strapi,\n tsconfig,\n options,\n });\n const contextDuration = timer.end('createBuildContext');\n contextSpinner.text = `Building build context (${prettyTime(contextDuration)})`;\n contextSpinner.succeed();\n\n timer.start('creatingAdmin');\n const adminSpinner = logger.spinner(`Creating admin`).start();\n\n await writeStaticClientFiles(ctx);\n\n if (ctx.bundler === 'webpack') {\n const { watch: watchWebpack } = await import('./webpack/watch');\n bundleWatcher = await watchWebpack(ctx);\n } else if (ctx.bundler === 'vite') {\n const { watch: watchVite } = await import('./vite/watch');\n bundleWatcher = await watchVite(ctx);\n }\n\n const adminDuration = timer.end('creatingAdmin');\n adminSpinner.text = `Creating admin (${prettyTime(adminDuration)})`;\n adminSpinner.succeed();\n }\n\n const loadStrapiDuration = timer.end('loadStrapi');\n loadStrapiSpinner.text = `Loading Strapi (${prettyTime(loadStrapiDuration)})`;\n loadStrapiSpinner.succeed();\n\n // For TS projects, type generation is a requirement for the develop command so that the server can restart\n // For JS projects, we respect the experimental autogenerate setting\n if (tsconfig?.config || strapi.config.get('typescript.autogenerate') !== false) {\n timer.start('generatingTS');\n const generatingTsSpinner = logger.spinner(`Generating types`).start();\n\n await tsUtils.generators.generate({\n strapi: strapiInstance,\n pwd: cwd,\n rootDir: undefined,\n logger: { silent: true, debug: false },\n artifacts: { contentTypes: true, components: true },\n });\n\n const generatingDuration = timer.end('generatingTS');\n generatingTsSpinner.text = `Generating types (${prettyTime(generatingDuration)})`;\n generatingTsSpinner.succeed();\n }\n\n if (tsconfig?.config) {\n timer.start('compilingTS');\n const compilingTsSpinner = logger.spinner(`Compiling TS`).start();\n\n await cleanupDistDirectory({ tsconfig, logger, timer });\n await tsUtils.compile(cwd, { configOptions: { ignoreDiagnostics: false } });\n\n const compilingDuration = timer.end('compilingTS');\n compilingTsSpinner.text = `Compiling TS (${prettyTime(compilingDuration)})`;\n compilingTsSpinner.succeed();\n }\n\n const restart = async () => {\n if (strapiInstance.reload.isWatching && !strapiInstance.reload.isReloading) {\n strapiInstance.reload.isReloading = true;\n strapiInstance.reload();\n }\n };\n\n const watcher = chokidar\n .watch(cwd, {\n ignoreInitial: true,\n usePolling: polling,\n ignored: [\n /(^|[/\\\\])\\../, // dot files\n /tmp/,\n '**/src/admin/**',\n '**/src/plugins/**/admin/**',\n '**/dist/src/plugins/test/admin/**',\n '**/documentation',\n '**/documentation/**',\n '**/node_modules',\n '**/node_modules/**',\n '**/plugins.json',\n '**/build',\n '**/build/**',\n '**/log',\n '**/log/**',\n '**/logs',\n '**/logs/**',\n '**/*.log',\n '**/index.html',\n '**/public',\n '**/public/**',\n strapiInstance.dirs.static.public,\n strings.joinBy('/', strapiInstance.dirs.static.public, '**'),\n '**/*.db*',\n '**/exports/**',\n '**/dist/**',\n '**/*.d.ts',\n '**/.yalc/**',\n '**/yalc.lock',\n // TODO v6: watch only src folder by default, and flip this to watchIncludeFiles\n ...strapiInstance.config.get('admin.watchIgnoreFiles', []),\n ],\n })\n .on('add', (path) => {\n strapiInstance.log.info(`File created: ${path}`);\n restart();\n })\n .on('change', (path) => {\n strapiInstance.log.info(`File changed: ${path}`);\n restart();\n })\n .on('unlink', (path) => {\n strapiInstance.log.info(`File deleted: ${path}`);\n restart();\n });\n\n process.on('message', async (message) => {\n switch (message) {\n case 'kill': {\n logger.debug(\n 'child process has the kill message, destroying the strapi instance and sending the killed process message'\n );\n await watcher.close();\n\n await strapiInstance.destroy();\n\n if (bundleWatcher) {\n bundleWatcher.close();\n }\n process.send?.('killed');\n break;\n }\n default:\n break;\n }\n });\n\n strapiInstance.start();\n }\n};\n\nexport { develop };\nexport type { DevelopOptions };\n"],"names":["cleanupDistDirectory","tsconfig","logger","timer","distDir","config","options","outDir","fs","access","then","catch","timerName","Date","now","start","cleaningSpinner","spinner","dirContent","readdir","validFilenames","filter","filename","rm","path","resolve","recursive","err","generatingDuration","end","text","prettyTime","fail","succeed","develop","cwd","polling","watchAdmin","getTimer","cluster","isPrimary","didInstall","checkRequiredDependencies","error","message","process","exit","tsUtils","compile","configOptions","ignoreDiagnostics","contextSpinner","console","log","ctx","createBuildContext","contextDuration","adminSpinner","writeStaticClientFiles","bundler","build","buildWebpack","buildVite","adminDuration","on","worker","debug","send","fork","isWorker","loadStrapiSpinner","strapi","createStrapi","appDir","autoReload","serveAdminPanel","bundleWatcher","strapiInstance","load","watch","watchWebpack","watchVite","loadStrapiDuration","get","generatingTsSpinner","generators","generate","pwd","rootDir","undefined","silent","artifacts","contentTypes","components","compilingTsSpinner","compilingDuration","restart","reload","isWatching","isReloading","watcher","chokidar","ignoreInitial","usePolling","ignored","dirs","static","public","strings","joinBy","info","close","destroy"],"mappings":";;;;;;;;;;;;AA6BA;AACA,MAAMA,oBAAAA,GAAuB,OAAO,EAClCC,QAAQ,EACRC,MAAM,EACNC,KAAK,EACiE,GAAA;IACtE,MAAMC,OAAAA,GAAUH,QAAUI,EAAAA,MAAAA,EAAQC,OAASC,EAAAA,MAAAA;IAE3C,IACE,CAACH;AACA,IAAA,MAAMI,EACJC,CAAAA,MAAM,CAACL,OAAAA,CAAAA,CACPM,IAAI,CAAC,IAAM,KAAA,CAAA,CACXC,KAAK,CAAC,IAAM,IAAA,CAAA;AACf,MAAA;AACA,QAAA;AACF;AAEA,IAAA,MAAMC,YAAY,CAAC,YAAY,EAAEC,IAAKC,CAAAA,GAAG,GAAG,CAAC;AAC7CX,IAAAA,KAAAA,CAAMY,KAAK,CAACH,SAAAA,CAAAA;IACZ,MAAMI,eAAAA,GAAkBd,MAAOe,CAAAA,OAAO,CAAC,CAAC,kBAAkB,EAAEb,OAAAA,CAAQ,CAAC,CAAA,CAAEW,KAAK,EAAA;IAE5E,IAAI;AACF,QAAA,MAAMG,UAAa,GAAA,MAAMV,EAAGW,CAAAA,OAAO,CAACf,OAAAA,CAAAA;QACpC,MAAMgB,cAAAA,GAAiBF,UACrB;SACCG,MAAM,CAAC,CAACC,QAAAA,GAAaA,QAAa,KAAA,OAAA,CAAA;QACrC,KAAK,MAAMA,YAAYF,cAAgB,CAAA;AACrC,YAAA,MAAMZ,GAAGe,EAAE,CAACC,KAAKC,OAAO,CAACrB,SAASkB,QAAW,CAAA,EAAA;gBAAEI,SAAW,EAAA;AAA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CAACyD,IAAI,CAAC,CAAC,cAAc,EAAEtF,KAAK,CAAC,CAAA;AAC/CwE,YAAAA,OAAAA,EAAAA;SAEDhC,CAAAA,CAAAA,EAAE,CAAC,QAAA,EAAU,CAACxC,IAAAA,GAAAA;YACbqD,cAAexB,CAAAA,GAAG,CAACyD,IAAI,CAAC,CAAC,cAAc,EAAEtF,KAAK,CAAC,CAAA;AAC/CwE,YAAAA,OAAAA,EAAAA;SAEDhC,CAAAA,CAAAA,EAAE,CAAC,QAAA,EAAU,CAACxC,IAAAA,GAAAA;YACbqD,cAAexB,CAAAA,GAAG,CAACyD,IAAI,CAAC,CAAC,cAAc,EAAEtF,KAAK,CAAC,CAAA;AAC/CwE,YAAAA,OAAAA,EAAAA;AACF,SAAA,CAAA;QAEFnD,OAAQmB,CAAAA,EAAE,CAAC,SAAA,EAAW,OAAOpB,OAAAA,GAAAA;YAC3B,OAAQA,OAAAA;gBACN,KAAK,MAAA;AAAQ,oBAAA;AACX1C,wBAAAA,MAAAA,CAAOgE,KAAK,CACV,2GAAA,CAAA;AAEF,wBAAA,MAAMkC,QAAQW,KAAK,EAAA;AAEnB,wBAAA,MAAMlC,eAAemC,OAAO,EAAA;AAE5B,wBAAA,IAAIpC,aAAe,EAAA;AACjBA,4BAAAA,aAAAA,CAAcmC,KAAK,EAAA;AACrB;AACAlE,wBAAAA,OAAAA,CAAQsB,IAAI,GAAG,QAAA,CAAA;AACf,wBAAA;AACF;AAGF;AACF,SAAA,CAAA;AAEAU,QAAAA,cAAAA,CAAe9D,KAAK,EAAA;AACtB;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"develop.mjs","sources":["../../../src/node/develop.ts"],"sourcesContent":["import * as tsUtils from '@strapi/typescript-utils';\nimport { strings } from '@strapi/utils';\nimport chokidar from 'chokidar';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport cluster from 'node:cluster';\nimport { createStrapi } from '@strapi/core';\n\nimport type { CLIContext } from '../cli/types';\nimport { checkRequiredDependencies } from './core/dependencies';\nimport { getTimer, prettyTime, type TimeMeasurer } from './core/timer';\nimport { createBuildContext } from './create-build-context';\nimport type { WebpackWatcher } from './webpack/watch';\nimport type { ViteWatcher } from './vite/watch';\n\nimport { writeStaticClientFiles } from './staticFiles';\n\ninterface DevelopOptions extends CLIContext {\n /**\n * Which bundler to use for building.\n *\n * @default webpack\n */\n bundler?: 'webpack' | 'vite';\n polling?: boolean;\n open?: boolean;\n watchAdmin?: boolean;\n}\n\n// This method removes all non-admin build files from the dist directory\nconst cleanupDistDirectory = async ({\n tsconfig,\n logger,\n timer,\n}: Pick<DevelopOptions, 'tsconfig' | 'logger'> & { timer: TimeMeasurer }) => {\n const distDir = tsconfig?.config?.options?.outDir;\n\n if (\n !distDir || // we don't have a dist dir\n (await fs\n .access(distDir)\n .then(() => false)\n .catch(() => true)) // it doesn't exist -- if it does but no access, that will be caught later\n ) {\n return;\n }\n\n const timerName = `cleaningDist${Date.now()}`;\n timer.start(timerName);\n const cleaningSpinner = logger.spinner(`Cleaning dist dir ${distDir}`).start();\n\n try {\n const dirContent = await fs.readdir(distDir);\n const validFilenames = dirContent\n // Ignore the admin build folder\n .filter((filename) => filename !== 'build');\n for (const filename of validFilenames) {\n await fs.rm(path.resolve(distDir, filename), { recursive: true });\n }\n } catch (err: unknown) {\n const generatingDuration = timer.end(timerName);\n cleaningSpinner.text = `Error cleaning dist dir: ${err} (${prettyTime(generatingDuration)})`;\n cleaningSpinner?.fail();\n return;\n }\n\n const generatingDuration = timer.end(timerName);\n cleaningSpinner.text = `Cleaning dist dir (${prettyTime(generatingDuration)})`;\n cleaningSpinner?.succeed();\n};\n\nconst develop = async ({\n cwd,\n polling,\n logger,\n tsconfig,\n watchAdmin,\n ...options\n}: DevelopOptions) => {\n const timer = getTimer();\n\n if (cluster.isPrimary) {\n const { didInstall } = await checkRequiredDependencies({ cwd, logger }).catch((err) => {\n logger.error(err.message);\n process.exit(1);\n });\n\n if (didInstall) {\n return;\n }\n\n if (tsconfig?.config) {\n // Build without diagnostics in case schemas have changed\n await cleanupDistDirectory({ tsconfig, logger, timer });\n await tsUtils.compile(cwd, { configOptions: { ignoreDiagnostics: true } });\n }\n\n /**\n * IF we're not watching the admin we're going to build it, this makes\n * sure that at least the admin is built for users & they can interact\n * with the application.\n */\n if (!watchAdmin) {\n timer.start('createBuildContext');\n const contextSpinner = logger.spinner(`Building build context`).start();\n console.log('');\n\n const ctx = await createBuildContext({\n cwd,\n logger,\n tsconfig,\n options,\n });\n const contextDuration = timer.end('createBuildContext');\n contextSpinner.text = `Building build context (${prettyTime(contextDuration)})`;\n contextSpinner.succeed();\n\n timer.start('creatingAdmin');\n const adminSpinner = logger.spinner(`Creating admin`).start();\n\n await writeStaticClientFiles(ctx);\n\n if (ctx.bundler === 'webpack') {\n const { build: buildWebpack } = await import('./webpack/build');\n await buildWebpack(ctx);\n } else if (ctx.bundler === 'vite') {\n const { build: buildVite } = await import('./vite/build');\n await buildVite(ctx);\n }\n\n const adminDuration = timer.end('creatingAdmin');\n adminSpinner.text = `Creating admin (${prettyTime(adminDuration)})`;\n adminSpinner.succeed();\n }\n\n cluster.on('message', async (worker, message) => {\n switch (message) {\n case 'reload': {\n if (tsconfig?.config) {\n // Build without diagnostics in case schemas have changed\n await cleanupDistDirectory({ tsconfig, logger, timer });\n await tsUtils.compile(cwd, { configOptions: { ignoreDiagnostics: true } });\n }\n logger.debug('cluster has the reload message, sending the worker kill message');\n worker.send('kill');\n break;\n }\n case 'killed': {\n logger.debug('cluster has the killed message, forking the cluster');\n cluster.fork();\n break;\n }\n case 'stop': {\n process.exit(1);\n break;\n }\n default:\n break;\n }\n });\n\n cluster.fork();\n }\n\n if (cluster.isWorker) {\n timer.start('loadStrapi');\n const loadStrapiSpinner = logger.spinner(`Loading Strapi`).start();\n\n const strapi = createStrapi({\n appDir: cwd,\n distDir: tsconfig?.config.options.outDir ?? '',\n autoReload: true,\n serveAdminPanel: !watchAdmin,\n });\n\n /**\n * If we're watching the admin panel then we're going to attach the watcher\n * as a strapi middleware.\n */\n let bundleWatcher: WebpackWatcher | ViteWatcher | undefined;\n\n const strapiInstance = await strapi.load();\n\n if (watchAdmin) {\n timer.start('createBuildContext');\n const contextSpinner = logger.spinner(`Building build context`).start();\n console.log('');\n\n const ctx = await createBuildContext({\n cwd,\n logger,\n strapi,\n tsconfig,\n options,\n });\n const contextDuration = timer.end('createBuildContext');\n contextSpinner.text = `Building build context (${prettyTime(contextDuration)})`;\n contextSpinner.succeed();\n\n timer.start('creatingAdmin');\n const adminSpinner = logger.spinner(`Creating admin`).start();\n\n await writeStaticClientFiles(ctx);\n\n if (ctx.bundler === 'webpack') {\n const { watch: watchWebpack } = await import('./webpack/watch');\n bundleWatcher = await watchWebpack(ctx);\n } else if (ctx.bundler === 'vite') {\n const { watch: watchVite } = await import('./vite/watch');\n bundleWatcher = await watchVite(ctx);\n }\n\n const adminDuration = timer.end('creatingAdmin');\n adminSpinner.text = `Creating admin (${prettyTime(adminDuration)})`;\n adminSpinner.succeed();\n }\n\n const loadStrapiDuration = timer.end('loadStrapi');\n loadStrapiSpinner.text = `Loading Strapi (${prettyTime(loadStrapiDuration)})`;\n loadStrapiSpinner.succeed();\n\n // For TS projects, type generation is a requirement for the develop command so that the server can restart\n // For JS projects, we respect the experimental autogenerate setting\n if (tsconfig?.config || strapi.config.get('typescript.autogenerate') !== false) {\n timer.start('generatingTS');\n const generatingTsSpinner = logger.spinner(`Generating types`).start();\n\n await tsUtils.generators.generate({\n strapi: strapiInstance,\n pwd: cwd,\n rootDir: undefined,\n logger: { silent: true, debug: false },\n artifacts: { contentTypes: true, components: true },\n });\n\n const generatingDuration = timer.end('generatingTS');\n generatingTsSpinner.text = `Generating types (${prettyTime(generatingDuration)})`;\n generatingTsSpinner.succeed();\n }\n\n if (tsconfig?.config) {\n timer.start('compilingTS');\n const compilingTsSpinner = logger.spinner(`Compiling TS`).start();\n\n await cleanupDistDirectory({ tsconfig, logger, timer });\n await tsUtils.compile(cwd, { configOptions: { ignoreDiagnostics: false } });\n\n const compilingDuration = timer.end('compilingTS');\n compilingTsSpinner.text = `Compiling TS (${prettyTime(compilingDuration)})`;\n compilingTsSpinner.succeed();\n }\n\n const restart = async () => {\n if (strapiInstance.reload.isWatching && !strapiInstance.reload.isReloading) {\n strapiInstance.reload.isReloading = true;\n strapiInstance.reload();\n }\n };\n\n const watcher = chokidar\n .watch(cwd, {\n ignoreInitial: true,\n usePolling: polling,\n ignored: [\n /(^|[/\\\\])\\../, // dot files\n /tmp/,\n '**/src/admin/**',\n '**/src/plugins/**/admin/**',\n '**/dist/src/plugins/test/admin/**',\n '**/documentation',\n '**/documentation/**',\n '**/node_modules',\n '**/node_modules/**',\n '**/plugins.json',\n '**/build',\n '**/build/**',\n '**/log',\n '**/log/**',\n '**/logs',\n '**/logs/**',\n '**/*.log',\n '**/index.html',\n '**/public',\n '**/public/**',\n strapiInstance.dirs.static.public,\n strings.joinBy('/', strapiInstance.dirs.static.public, '**'),\n '**/*.db*',\n '**/exports/**',\n '**/dist/**',\n '**/*.d.ts',\n '**/.yalc/**',\n '**/yalc.lock',\n // TODO v6: watch only src folder by default, and flip this to watchIncludeFiles\n ...strapiInstance.config.get('admin.watchIgnoreFiles', []),\n ],\n })\n .on('add', (path) => {\n strapiInstance.log.info(`File created: ${path}`);\n restart();\n })\n .on('change', (path) => {\n strapiInstance.log.info(`File changed: ${path}`);\n restart();\n })\n .on('unlink', (path) => {\n strapiInstance.log.info(`File deleted: ${path}`);\n restart();\n });\n\n process.on('message', async (message) => {\n switch (message) {\n case 'kill': {\n logger.debug(\n 'child process has the kill message, destroying the strapi instance and sending the killed process message'\n );\n await watcher.close();\n\n await strapiInstance.destroy();\n\n if (bundleWatcher) {\n bundleWatcher.close();\n }\n process.send?.('killed');\n break;\n }\n default:\n break;\n }\n });\n\n strapiInstance.start();\n }\n};\n\nexport { develop };\nexport type { DevelopOptions };\n"],"names":["cleanupDistDirectory","tsconfig","logger","timer","distDir","config","options","outDir","fs","access","then","catch","timerName","Date","now","start","cleaningSpinner","spinner","dirContent","readdir","validFilenames","filter","filename","rm","path","resolve","recursive","err","generatingDuration","end","text","prettyTime","fail","succeed","develop","cwd","polling","watchAdmin","getTimer","cluster","isPrimary","didInstall","checkRequiredDependencies","error","message","process","exit","tsUtils","compile","configOptions","ignoreDiagnostics","contextSpinner","console","log","ctx","createBuildContext","contextDuration","adminSpinner","writeStaticClientFiles","bundler","build","buildWebpack","buildVite","adminDuration","on","worker","debug","send","fork","isWorker","loadStrapiSpinner","strapi","createStrapi","appDir","autoReload","serveAdminPanel","bundleWatcher","strapiInstance","load","watch","watchWebpack","watchVite","loadStrapiDuration","get","generatingTsSpinner","generators","generate","pwd","rootDir","undefined","silent","artifacts","contentTypes","components","compilingTsSpinner","compilingDuration","restart","reload","isWatching","isReloading","watcher","chokidar","ignoreInitial","usePolling","ignored","dirs","static","public","strings","joinBy","info","close","destroy"],"mappings":";;;;;;;;;;;;AA6BA;AACA,MAAMA,oBAAAA,GAAuB,OAAO,EAClCC,QAAQ,EACRC,MAAM,EACNC,KAAK,EACiE,GAAA;IACtE,MAAMC,OAAAA,GAAUH,QAAUI,EAAAA,MAAAA,EAAQC,OAASC,EAAAA,MAAAA;IAE3C,IACE,CAACH;AACA,IAAA,MAAMI,EACJC,CAAAA,MAAM,CAACL,OAAAA,CAAAA,CACPM,IAAI,CAAC,IAAM,KAAA,CAAA,CACXC,KAAK,CAAC,IAAM,IAAA,CAAA;AACf,MAAA;AACA,QAAA;AACF;AAEA,IAAA,MAAMC,YAAY,CAAC,YAAY,EAAEC,IAAAA,CAAKC,GAAG,EAAI,CAAA,CAAA;AAC7CX,IAAAA,KAAAA,CAAMY,KAAK,CAACH,SAAAA,CAAAA;IACZ,MAAMI,eAAAA,GAAkBd,OAAOe,OAAO,CAAC,CAAC,kBAAkB,EAAEb,OAAS,CAAA,CAAA,CAAA,CAAEW,KAAK,EAAA;IAE5E,IAAI;AACF,QAAA,MAAMG,UAAa,GAAA,MAAMV,EAA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SAAA,CAAA;AAEAU,QAAAA,cAAAA,CAAe9D,KAAK,EAAA;AACtB;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staticFiles.js","sources":["../../../src/node/staticFiles.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport outdent from 'outdent';\nimport { createElement } from 'react';\nimport { renderToStaticMarkup } from 'react-dom/server';\nimport { DefaultDocument } from '@strapi/admin/_internal';\n\nimport type { BuildContext } from './create-build-context';\n\nconst getEntryModule = (ctx: BuildContext): string => {\n const pluginsObject = ctx.plugins\n .map(({ name, importName }) => `'${name}': ${importName}`)\n .join(',\\n');\n\n const pluginsImport = ctx.plugins\n .map(({ importName, modulePath }) => `import ${importName} from '${modulePath}';`)\n .join('\\n');\n\n return outdent`\n /**\n * This file was automatically generated by Strapi.\n * Any modifications made will be discarded.\n */\n ${pluginsImport}\n import { renderAdmin } from \"@strapi/strapi/admin\"\n\n ${\n ctx.customisations?.modulePath\n ? `import customisations from '${ctx.customisations.modulePath}'`\n : ''\n }\n\n renderAdmin(\n document.getElementById(\"strapi\"),\n {\n ${ctx.customisations?.modulePath ? 'customisations,' : ''}\n ${ctx.features ? `features: ${JSON.stringify(ctx.features)},` : ''}\n plugins: {\n ${pluginsObject}\n }\n })\n `;\n};\n\ninterface GetDocumentHTMLArgs extends Pick<BuildContext, 'logger'> {\n props?: {\n entryPath?: string;\n };\n}\n\n/**\n * TODO: Here in the future we could add the ability\n * to load a user's Document component?\n */\nconst getDocumentHTML = ({ logger, props = {} }: GetDocumentHTMLArgs) => {\n const result = renderToStaticMarkup(createElement(DefaultDocument, props));\n logger.debug('Rendered the HTML');\n\n return outdent`<!DOCTYPE html>${result}`;\n};\n\nconst AUTO_GENERATED_WARNING = `\nThis file was automatically generated by Strapi.\nAny modifications made will be discarded.\n`.trim();\n\n/**\n * Because we now auto-generate the index.html file,\n * we should be clear that people _should not_ modify it.\n *\n * @internal\n */\nconst decorateHTMLWithAutoGeneratedWarning = (htmlTemplate: string): string =>\n htmlTemplate.replace(/<head/, `\\n<!--\\n${AUTO_GENERATED_WARNING}\\n-->\\n<head`);\n\nconst writeStaticClientFiles = async (ctx: BuildContext) => {\n const prettier = await import('prettier'); // ESM-only\n\n /**\n * For everything to work effectively we create a client folder in `.strapi` at the cwd level.\n * We then use the function we need to \"createAdmin\" as well as generate the Document index.html as well.\n *\n * All this links together an imaginary \"src/index\" that then allows vite to correctly build the admin panel.\n */\n\n await fs.mkdir(ctx.runtimeDir, { recursive: true });\n ctx.logger.debug('Created the runtime directory');\n\n const indexHtml = decorateHTMLWithAutoGeneratedWarning(\n await getDocumentHTML({\n logger: ctx.logger,\n props:\n ctx.bundler === 'vite'\n ? {\n entryPath: `/${ctx.entry}`,\n }\n : undefined,\n })\n );\n\n await fs.writeFile(\n path.join(ctx.runtimeDir, 'index.html'),\n await prettier.format(indexHtml, {\n parser: 'html',\n })\n );\n ctx.logger.debug('Wrote the index.html file');\n await fs.writeFile(\n path.join(ctx.runtimeDir, 'app.js'),\n await prettier.format(getEntryModule(ctx), {\n parser: 'babel',\n })\n );\n ctx.logger.debug('Wrote the app.js file');\n};\n\nexport { writeStaticClientFiles, getDocumentHTML };\n"],"names":["getEntryModule","ctx","pluginsObject","plugins","map","name","importName","join","pluginsImport","modulePath","outdent","customisations","features","JSON","stringify","getDocumentHTML","logger","props","result","renderToStaticMarkup","createElement","DefaultDocument","debug","AUTO_GENERATED_WARNING","trim","decorateHTMLWithAutoGeneratedWarning","htmlTemplate","replace","writeStaticClientFiles","prettier","fs","mkdir","runtimeDir","recursive","indexHtml","bundler","entryPath","entry","undefined","writeFile","path","format","parser"],"mappings":";;;;;;;;;AASA,MAAMA,iBAAiB,CAACC,GAAAA,GAAAA;IACtB,MAAMC,aAAAA,GAAgBD,IAAIE,OAAO,CAC9BC,GAAG,CAAC,CAAC,EAAEC,IAAI,EAAEC,UAAU,EAAE,GAAK,CAAC,CAAC,EAAED,
|
|
1
|
+
{"version":3,"file":"staticFiles.js","sources":["../../../src/node/staticFiles.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport outdent from 'outdent';\nimport { createElement } from 'react';\nimport { renderToStaticMarkup } from 'react-dom/server';\nimport { DefaultDocument } from '@strapi/admin/_internal';\n\nimport type { BuildContext } from './create-build-context';\n\nconst getEntryModule = (ctx: BuildContext): string => {\n const pluginsObject = ctx.plugins\n .map(({ name, importName }) => `'${name}': ${importName}`)\n .join(',\\n');\n\n const pluginsImport = ctx.plugins\n .map(({ importName, modulePath }) => `import ${importName} from '${modulePath}';`)\n .join('\\n');\n\n return outdent`\n /**\n * This file was automatically generated by Strapi.\n * Any modifications made will be discarded.\n */\n ${pluginsImport}\n import { renderAdmin } from \"@strapi/strapi/admin\"\n\n ${\n ctx.customisations?.modulePath\n ? `import customisations from '${ctx.customisations.modulePath}'`\n : ''\n }\n\n renderAdmin(\n document.getElementById(\"strapi\"),\n {\n ${ctx.customisations?.modulePath ? 'customisations,' : ''}\n ${ctx.features ? `features: ${JSON.stringify(ctx.features)},` : ''}\n plugins: {\n ${pluginsObject}\n }\n })\n `;\n};\n\ninterface GetDocumentHTMLArgs extends Pick<BuildContext, 'logger'> {\n props?: {\n entryPath?: string;\n };\n}\n\n/**\n * TODO: Here in the future we could add the ability\n * to load a user's Document component?\n */\nconst getDocumentHTML = ({ logger, props = {} }: GetDocumentHTMLArgs) => {\n const result = renderToStaticMarkup(createElement(DefaultDocument, props));\n logger.debug('Rendered the HTML');\n\n return outdent`<!DOCTYPE html>${result}`;\n};\n\nconst AUTO_GENERATED_WARNING = `\nThis file was automatically generated by Strapi.\nAny modifications made will be discarded.\n`.trim();\n\n/**\n * Because we now auto-generate the index.html file,\n * we should be clear that people _should not_ modify it.\n *\n * @internal\n */\nconst decorateHTMLWithAutoGeneratedWarning = (htmlTemplate: string): string =>\n htmlTemplate.replace(/<head/, `\\n<!--\\n${AUTO_GENERATED_WARNING}\\n-->\\n<head`);\n\nconst writeStaticClientFiles = async (ctx: BuildContext) => {\n const prettier = await import('prettier'); // ESM-only\n\n /**\n * For everything to work effectively we create a client folder in `.strapi` at the cwd level.\n * We then use the function we need to \"createAdmin\" as well as generate the Document index.html as well.\n *\n * All this links together an imaginary \"src/index\" that then allows vite to correctly build the admin panel.\n */\n\n await fs.mkdir(ctx.runtimeDir, { recursive: true });\n ctx.logger.debug('Created the runtime directory');\n\n const indexHtml = decorateHTMLWithAutoGeneratedWarning(\n await getDocumentHTML({\n logger: ctx.logger,\n props:\n ctx.bundler === 'vite'\n ? {\n entryPath: `/${ctx.entry}`,\n }\n : undefined,\n })\n );\n\n await fs.writeFile(\n path.join(ctx.runtimeDir, 'index.html'),\n await prettier.format(indexHtml, {\n parser: 'html',\n })\n );\n ctx.logger.debug('Wrote the index.html file');\n await fs.writeFile(\n path.join(ctx.runtimeDir, 'app.js'),\n await prettier.format(getEntryModule(ctx), {\n parser: 'babel',\n })\n );\n ctx.logger.debug('Wrote the app.js file');\n};\n\nexport { writeStaticClientFiles, getDocumentHTML };\n"],"names":["getEntryModule","ctx","pluginsObject","plugins","map","name","importName","join","pluginsImport","modulePath","outdent","customisations","features","JSON","stringify","getDocumentHTML","logger","props","result","renderToStaticMarkup","createElement","DefaultDocument","debug","AUTO_GENERATED_WARNING","trim","decorateHTMLWithAutoGeneratedWarning","htmlTemplate","replace","writeStaticClientFiles","prettier","fs","mkdir","runtimeDir","recursive","indexHtml","bundler","entryPath","entry","undefined","writeFile","path","format","parser"],"mappings":";;;;;;;;;AASA,MAAMA,iBAAiB,CAACC,GAAAA,GAAAA;IACtB,MAAMC,aAAAA,GAAgBD,IAAIE,OAAO,CAC9BC,GAAG,CAAC,CAAC,EAAEC,IAAI,EAAEC,UAAU,EAAE,GAAK,CAAC,CAAC,EAAED,IAAAA,CAAK,GAAG,EAAEC,UAAAA,CAAAA,CAAY,CACxDC,CAAAA,IAAI,CAAC,KAAA,CAAA;IAER,MAAMC,aAAAA,GAAgBP,GAAIE,C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AA,MAAM4B,QAAW,GAAA,MAAM,OAAO;AAE9B;;;;;AAKC,MAED,MAAMC,EAAGC,CAAAA,KAAK,CAAC9B,GAAAA,CAAI+B,UAAU,EAAE;QAAEC,SAAW,EAAA;AAAK,KAAA,CAAA;IACjDhC,GAAIe,CAAAA,MAAM,CAACM,KAAK,CAAC,+BAAA,CAAA;IAEjB,MAAMY,SAAAA,GAAYT,oCAChB,CAAA,MAAMV,eAAgB,CAAA;AACpBC,QAAAA,MAAAA,EAAQf,IAAIe,MAAM;QAClBC,KACEhB,EAAAA,GAAAA,CAAIkC,OAAO,KAAK,MACZ,GAAA;AACEC,YAAAA,SAAAA,EAAW,CAAC,CAAC,EAAEnC,GAAAA,CAAIoC,KAAK,CAAE;SAE5BC,GAAAA;AACR,KAAA,CAAA,CAAA;AAGF,IAAA,MAAMR,EAAGS,CAAAA,SAAS,CAChBC,IAAAA,CAAKjC,IAAI,CAACN,GAAAA,CAAI+B,UAAU,EAAE,YAC1B,CAAA,EAAA,MAAMH,QAASY,CAAAA,MAAM,CAACP,SAAW,EAAA;QAC/BQ,MAAQ,EAAA;AACV,KAAA,CAAA,CAAA;IAEFzC,GAAIe,CAAAA,MAAM,CAACM,KAAK,CAAC,2BAAA,CAAA;AACjB,IAAA,MAAMQ,EAAGS,CAAAA,SAAS,CAChBC,IAAAA,CAAKjC,IAAI,CAACN,GAAAA,CAAI+B,UAAU,EAAE,WAC1B,MAAMH,QAAAA,CAASY,MAAM,CAACzC,eAAeC,GAAM,CAAA,EAAA;QACzCyC,MAAQ,EAAA;AACV,KAAA,CAAA,CAAA;IAEFzC,GAAIe,CAAAA,MAAM,CAACM,KAAK,CAAC,uBAAA,CAAA;AACnB;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staticFiles.mjs","sources":["../../../src/node/staticFiles.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport outdent from 'outdent';\nimport { createElement } from 'react';\nimport { renderToStaticMarkup } from 'react-dom/server';\nimport { DefaultDocument } from '@strapi/admin/_internal';\n\nimport type { BuildContext } from './create-build-context';\n\nconst getEntryModule = (ctx: BuildContext): string => {\n const pluginsObject = ctx.plugins\n .map(({ name, importName }) => `'${name}': ${importName}`)\n .join(',\\n');\n\n const pluginsImport = ctx.plugins\n .map(({ importName, modulePath }) => `import ${importName} from '${modulePath}';`)\n .join('\\n');\n\n return outdent`\n /**\n * This file was automatically generated by Strapi.\n * Any modifications made will be discarded.\n */\n ${pluginsImport}\n import { renderAdmin } from \"@strapi/strapi/admin\"\n\n ${\n ctx.customisations?.modulePath\n ? `import customisations from '${ctx.customisations.modulePath}'`\n : ''\n }\n\n renderAdmin(\n document.getElementById(\"strapi\"),\n {\n ${ctx.customisations?.modulePath ? 'customisations,' : ''}\n ${ctx.features ? `features: ${JSON.stringify(ctx.features)},` : ''}\n plugins: {\n ${pluginsObject}\n }\n })\n `;\n};\n\ninterface GetDocumentHTMLArgs extends Pick<BuildContext, 'logger'> {\n props?: {\n entryPath?: string;\n };\n}\n\n/**\n * TODO: Here in the future we could add the ability\n * to load a user's Document component?\n */\nconst getDocumentHTML = ({ logger, props = {} }: GetDocumentHTMLArgs) => {\n const result = renderToStaticMarkup(createElement(DefaultDocument, props));\n logger.debug('Rendered the HTML');\n\n return outdent`<!DOCTYPE html>${result}`;\n};\n\nconst AUTO_GENERATED_WARNING = `\nThis file was automatically generated by Strapi.\nAny modifications made will be discarded.\n`.trim();\n\n/**\n * Because we now auto-generate the index.html file,\n * we should be clear that people _should not_ modify it.\n *\n * @internal\n */\nconst decorateHTMLWithAutoGeneratedWarning = (htmlTemplate: string): string =>\n htmlTemplate.replace(/<head/, `\\n<!--\\n${AUTO_GENERATED_WARNING}\\n-->\\n<head`);\n\nconst writeStaticClientFiles = async (ctx: BuildContext) => {\n const prettier = await import('prettier'); // ESM-only\n\n /**\n * For everything to work effectively we create a client folder in `.strapi` at the cwd level.\n * We then use the function we need to \"createAdmin\" as well as generate the Document index.html as well.\n *\n * All this links together an imaginary \"src/index\" that then allows vite to correctly build the admin panel.\n */\n\n await fs.mkdir(ctx.runtimeDir, { recursive: true });\n ctx.logger.debug('Created the runtime directory');\n\n const indexHtml = decorateHTMLWithAutoGeneratedWarning(\n await getDocumentHTML({\n logger: ctx.logger,\n props:\n ctx.bundler === 'vite'\n ? {\n entryPath: `/${ctx.entry}`,\n }\n : undefined,\n })\n );\n\n await fs.writeFile(\n path.join(ctx.runtimeDir, 'index.html'),\n await prettier.format(indexHtml, {\n parser: 'html',\n })\n );\n ctx.logger.debug('Wrote the index.html file');\n await fs.writeFile(\n path.join(ctx.runtimeDir, 'app.js'),\n await prettier.format(getEntryModule(ctx), {\n parser: 'babel',\n })\n );\n ctx.logger.debug('Wrote the app.js file');\n};\n\nexport { writeStaticClientFiles, getDocumentHTML };\n"],"names":["getEntryModule","ctx","pluginsObject","plugins","map","name","importName","join","pluginsImport","modulePath","outdent","customisations","features","JSON","stringify","getDocumentHTML","logger","props","result","renderToStaticMarkup","createElement","DefaultDocument","debug","AUTO_GENERATED_WARNING","trim","decorateHTMLWithAutoGeneratedWarning","htmlTemplate","replace","writeStaticClientFiles","prettier","fs","mkdir","runtimeDir","recursive","indexHtml","bundler","entryPath","entry","undefined","writeFile","path","format","parser"],"mappings":";;;;;;;AASA,MAAMA,iBAAiB,CAACC,GAAAA,GAAAA;IACtB,MAAMC,aAAAA,GAAgBD,IAAIE,OAAO,CAC9BC,GAAG,CAAC,CAAC,EAAEC,IAAI,EAAEC,UAAU,EAAE,GAAK,CAAC,CAAC,EAAED,
|
|
1
|
+
{"version":3,"file":"staticFiles.mjs","sources":["../../../src/node/staticFiles.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport outdent from 'outdent';\nimport { createElement } from 'react';\nimport { renderToStaticMarkup } from 'react-dom/server';\nimport { DefaultDocument } from '@strapi/admin/_internal';\n\nimport type { BuildContext } from './create-build-context';\n\nconst getEntryModule = (ctx: BuildContext): string => {\n const pluginsObject = ctx.plugins\n .map(({ name, importName }) => `'${name}': ${importName}`)\n .join(',\\n');\n\n const pluginsImport = ctx.plugins\n .map(({ importName, modulePath }) => `import ${importName} from '${modulePath}';`)\n .join('\\n');\n\n return outdent`\n /**\n * This file was automatically generated by Strapi.\n * Any modifications made will be discarded.\n */\n ${pluginsImport}\n import { renderAdmin } from \"@strapi/strapi/admin\"\n\n ${\n ctx.customisations?.modulePath\n ? `import customisations from '${ctx.customisations.modulePath}'`\n : ''\n }\n\n renderAdmin(\n document.getElementById(\"strapi\"),\n {\n ${ctx.customisations?.modulePath ? 'customisations,' : ''}\n ${ctx.features ? `features: ${JSON.stringify(ctx.features)},` : ''}\n plugins: {\n ${pluginsObject}\n }\n })\n `;\n};\n\ninterface GetDocumentHTMLArgs extends Pick<BuildContext, 'logger'> {\n props?: {\n entryPath?: string;\n };\n}\n\n/**\n * TODO: Here in the future we could add the ability\n * to load a user's Document component?\n */\nconst getDocumentHTML = ({ logger, props = {} }: GetDocumentHTMLArgs) => {\n const result = renderToStaticMarkup(createElement(DefaultDocument, props));\n logger.debug('Rendered the HTML');\n\n return outdent`<!DOCTYPE html>${result}`;\n};\n\nconst AUTO_GENERATED_WARNING = `\nThis file was automatically generated by Strapi.\nAny modifications made will be discarded.\n`.trim();\n\n/**\n * Because we now auto-generate the index.html file,\n * we should be clear that people _should not_ modify it.\n *\n * @internal\n */\nconst decorateHTMLWithAutoGeneratedWarning = (htmlTemplate: string): string =>\n htmlTemplate.replace(/<head/, `\\n<!--\\n${AUTO_GENERATED_WARNING}\\n-->\\n<head`);\n\nconst writeStaticClientFiles = async (ctx: BuildContext) => {\n const prettier = await import('prettier'); // ESM-only\n\n /**\n * For everything to work effectively we create a client folder in `.strapi` at the cwd level.\n * We then use the function we need to \"createAdmin\" as well as generate the Document index.html as well.\n *\n * All this links together an imaginary \"src/index\" that then allows vite to correctly build the admin panel.\n */\n\n await fs.mkdir(ctx.runtimeDir, { recursive: true });\n ctx.logger.debug('Created the runtime directory');\n\n const indexHtml = decorateHTMLWithAutoGeneratedWarning(\n await getDocumentHTML({\n logger: ctx.logger,\n props:\n ctx.bundler === 'vite'\n ? {\n entryPath: `/${ctx.entry}`,\n }\n : undefined,\n })\n );\n\n await fs.writeFile(\n path.join(ctx.runtimeDir, 'index.html'),\n await prettier.format(indexHtml, {\n parser: 'html',\n })\n );\n ctx.logger.debug('Wrote the index.html file');\n await fs.writeFile(\n path.join(ctx.runtimeDir, 'app.js'),\n await prettier.format(getEntryModule(ctx), {\n parser: 'babel',\n })\n );\n ctx.logger.debug('Wrote the app.js file');\n};\n\nexport { writeStaticClientFiles, getDocumentHTML };\n"],"names":["getEntryModule","ctx","pluginsObject","plugins","map","name","importName","join","pluginsImport","modulePath","outdent","customisations","features","JSON","stringify","getDocumentHTML","logger","props","result","renderToStaticMarkup","createElement","DefaultDocument","debug","AUTO_GENERATED_WARNING","trim","decorateHTMLWithAutoGeneratedWarning","htmlTemplate","replace","writeStaticClientFiles","prettier","fs","mkdir","runtimeDir","recursive","indexHtml","bundler","entryPath","entry","undefined","writeFile","path","format","parser"],"mappings":";;;;;;;AASA,MAAMA,iBAAiB,CAACC,GAAAA,GAAAA;IACtB,MAAMC,aAAAA,GAAgBD,IAAIE,OAAO,CAC9BC,GAAG,CAAC,CAAC,EAAEC,IAAI,EAAEC,UAAU,EAAE,GAAK,CAAC,CAAC,EAAED,IAAAA,CAAK,GAAG,EAAEC,UAAAA,CAAAA,CAAY,CACxDC,CAAAA,IAAI,CAAC,KAAA,CAAA;IAER,MAAMC,aAAAA,GAAgBP,GAAIE,CAAAA,OAAO,CAC9BC,GAAG,CAAC,CAAC,EAAEE,UAAU,EAAEG,UAAU,EAAE,GAAK,CAAC,OAAO,EAAEH,UAAAA,CAAW,OAAO,EAAEG,WAAW,EAAE,CAAC,CAChFF,CAAAA,IAAI,CAAC,IAAA,CAAA;AAER,IAAA,OAAOG,OAAO;;;;;AAKR,QAAA,EAAEF,aAAc;;;AAGhB,Q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