Merge pull request #13055 from strapi/typescript/fix-static-resources-resolution

[TS] Fix static resources resolution
This commit is contained in:
cyril lopez 2022-04-05 11:11:46 +02:00 committed by GitHub
commit 831726978a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 14 additions and 30 deletions

View File

@ -75,7 +75,7 @@ class Strapi {
const rootDirs = resolveWorkingDirectories(opts);
// Load the app configuration from the dist directory
const appConfig = loadConfiguration(rootDirs.dist, opts);
const appConfig = loadConfiguration({ appDir: rootDirs.app, distDir: rootDirs.dist }, opts);
// Instanciate the Strapi container
this.container = createContainer(this);

View File

@ -50,7 +50,7 @@ const primaryProcess = async ({ distDir, appDir, build, isTSProject, watchAdmin,
await buildTypeScript({ srcDir: appDir, distDir, watch: false });
}
const config = loadConfiguration(distDir);
const config = loadConfiguration({ appDir, distDir });
const serveAdminPanel = getOr(true, 'admin.serveAdminPanel')(config);
const buildExists = fs.existsSync(path.join(distDir, 'build'));
@ -171,8 +171,8 @@ function watchFileChanges({ appDir, strapiInstance, watchIgnoreFiles, polling })
'**/index.html',
'**/public',
'**/public/**',
strapiInstance.dirs.public,
joinBy('/', strapiInstance.dirs.public, '**'),
strapiInstance.dirs.static.public,
joinBy('/', strapiInstance.dirs.static.public, '**'),
'**/*.db*',
'**/exports/**',
'**/dist/**',

View File

@ -31,12 +31,13 @@ const defaultConfig = {
},
};
module.exports = (dir, initialConfig = {}) => {
module.exports = (dirs, initialConfig = {}) => {
const { appDir, distDir } = dirs;
const { autoReload = false, serveAdminPanel = true } = initialConfig;
const pkgJSON = require(path.resolve(dir, 'package.json'));
const pkgJSON = require(path.resolve(appDir, 'package.json'));
const configDir = path.resolve(dir || process.cwd(), 'config');
const configDir = path.resolve(distDir || process.cwd(), 'config');
const rootConfig = {
launchedAt: Date.now(),

View File

@ -81,7 +81,7 @@ module.exports = (config, { strapi }) => {
{
method: 'GET',
path: '/(.*)',
handler: koaStatic(strapi.dirs.app.public, {
handler: koaStatic(strapi.dirs.static.public, {
maxage: maxAge,
defer: true,
}),

View File

@ -25,7 +25,7 @@ module.exports = ({ strapi }) => {
{
method: 'GET',
path: '/uploads/(.*)',
handler: [range, koaStatic(strapi.dirs.app.public, { defer: true, ...localServerConfig })],
handler: [range, koaStatic(strapi.dirs.static.public, { defer: true, ...localServerConfig })],
config: { auth: false },
},
]);

View File

@ -1,5 +1,5 @@
import pluginPkg from '../../package.json';
const pluginId = pluginPkg.name.replace(/^@strapi\/plugin-/i, '');
const pluginId = pluginPkg.name.replace(/^(@[^-,.][\w,-]+\/|strapi-)plugin-/i, '');
export default pluginId;

View File

@ -2,7 +2,6 @@
const compilers = require('./compilers');
const getConfigPath = require('./utils/get-config-path');
const copyResources = require('./utils/copy-resources');
module.exports = async (srcDir, { watch = false } = {}) => {
// TODO: Use the Strapi debug logger instead or don't log at all
@ -12,6 +11,4 @@ module.exports = async (srcDir, { watch = false } = {}) => {
const configPath = getConfigPath(srcDir);
compiler.run(configPath);
await copyResources(srcDir);
};

View File

@ -1,12 +0,0 @@
'use strict';
const path = require('path');
const fse = require('fs-extra');
const DEFAULT_RESOURCES_PATHS = ['public', 'favicon.ico', 'package.json'];
module.exports = async (dir, resources = DEFAULT_RESOURCES_PATHS) => {
await Promise.all(
resources.map(resourceName => fse.copy(resourceName, path.join(dir, 'dist', resourceName)))
);
};

View File

@ -5,7 +5,6 @@ const isTypeScriptProjectSync = require('./is-typescript-project-sync');
const getConfigPath = require('./get-config-path');
const reportDiagnostics = require('./report-diagnostics');
const resolveConfigOptions = require('./resolve-config-options');
const copyResources = require('./copy-resources');
const formatHost = require('./format-host');
module.exports = {
@ -14,6 +13,5 @@ module.exports = {
getConfigPath,
reportDiagnostics,
resolveConfigOptions,
copyResources,
formatHost,
};

View File

@ -5636,9 +5636,9 @@
"@types/node" "*"
"@types/lodash@^4.14.165", "@types/lodash@^4.14.175":
version "4.14.179"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.179.tgz#490ec3288088c91295780237d2497a3aa9dfb5c5"
integrity sha512-uwc1x90yCKqGcIOAT6DwOSuxnrAbpkdPsUOZtwrXb4D/6wZs+6qG7QnIawDuZWg0sWpxl+ltIKCaLoMlna678w==
version "4.14.180"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.180.tgz#4ab7c9ddfc92ec4a887886483bc14c79fb380670"
integrity sha512-XOKXa1KIxtNXgASAnwj7cnttJxS4fksBRywK/9LzRV5YxrF80BXZIGeQSuoESQ/VkUj30Ae0+YcuHc15wJCB2g==
"@types/long@^4.0.0":
version "4.0.1"