Skip to content

Commit

Permalink
fix(deploy): adapt to the new server plugin for entry (#5870)
Browse files Browse the repository at this point in the history
  • Loading branch information
yimingjfe authored Jun 25, 2024
1 parent b50d7ec commit 8677d06
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/pink-drinks-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/app-tools': patch
---

fix: adapt to the new server plugin for entry
fix: server entry 适配新的 server plugin
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,14 @@ export const createNetlifyPreset: CreatePreset = (
const dynamicProdOptions = {
config: serverConfig,
serverConfigFile: DEFAULT_SERVER_CONFIG,
plugins,
};

const pluginsCode = `[${plugins
.map((plugin, index) => {
return `plugin_${index}()`;
})
.join(',')}]`;

let entryCode = (
await fse.readFile(path.join(__dirname, './netlifyEntry.js'))
).toString();
Expand All @@ -119,6 +124,7 @@ export const createNetlifyPreset: CreatePreset = (
.replace('p_genPluginImportsCode', pluginImportCode)
.replace('p_ROUTE_SPEC_FILE', `"${ROUTE_SPEC_FILE}"`)
.replace('p_dynamicProdOptions', JSON.stringify(dynamicProdOptions))
.replace('p_plugins', pluginsCode)
.replace('p_sharedDirectory', serverAppContext.sharedDirectory)
.replace('p_apiDirectory', serverAppContext.apiDirectory)
.replace('p_lambdaDirectory', serverAppContext.lambdaDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async function initServer() {
apiDirectory: p_apiDirectory,
lambdaDirectory: p_lambdaDirectory,
},
plugins: p_plugins,
...dynamicProdOptions,
};
const requestHandler = await createNetlifyFunction(prodServerOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ export const createNodePreset: CreatePreset = (appContext, config) => {
const dynamicProdOptions = {
config: serverConfig,
serverConfigFile: DEFAULT_SERVER_CONFIG,
plugins,
};

const pluginsCode = `[${plugins
.map((plugin, index) => {
return `plugin_${index}()`;
})
.join(',')}]`;

let entryCode = (
await fse.readFile(path.join(__dirname, './nodeEntry.js'))
).toString();
Expand All @@ -55,6 +60,7 @@ export const createNodePreset: CreatePreset = (appContext, config) => {
.replace('p_genPluginImportsCode', pluginImportCode)
.replace('p_ROUTE_SPEC_FILE', `"${ROUTE_SPEC_FILE}"`)
.replace('p_dynamicProdOptions', JSON.stringify(dynamicProdOptions))
.replace('p_plugins', pluginsCode)
.replace('p_sharedDirectory', serverAppContext.sharedDirectory)
.replace('p_apiDirectory', serverAppContext.apiDirectory)
.replace('p_lambdaDirectory', serverAppContext.lambdaDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async function main() {
apiDirectory: p_apiDirectory,
lambdaDirectory: p_lambdaDirectory,
},
plugins: p_plugins,
...dynamicProdOptions,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,14 @@ export const createVercelPreset: CreatePreset = (
const dynamicProdOptions = {
config: serverConfig,
serverConfigFile: DEFAULT_SERVER_CONFIG,
plugins,
};

const pluginsCode = `[${plugins
.map((plugin, index) => {
return `plugin_${index}()`;
})
.join(',')}]`;

const serverAppContext = serverAppContenxtTemplate(appContext);

let entryCode = (
Expand All @@ -127,6 +132,7 @@ export const createVercelPreset: CreatePreset = (
.replace('p_genPluginImportsCode', pluginImportCode)
.replace('p_ROUTE_SPEC_FILE', `"${ROUTE_SPEC_FILE}"`)
.replace('p_dynamicProdOptions', JSON.stringify(dynamicProdOptions))
.replace('p_plugins', pluginsCode)
.replace('p_sharedDirectory', serverAppContext.sharedDirectory)
.replace('p_apiDirectory', serverAppContext.apiDirectory)
.replace('p_lambdaDirectory', serverAppContext.lambdaDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async function initServer() {
apiDirectory: p_apiDirectory,
lambdaDirectory: p_lambdaDirectory,
},
plugins: p_plugins,
...dynamicProdOptions,
};
const app = await createProdServer(prodServerOptions);
Expand Down

0 comments on commit 8677d06

Please sign in to comment.