Skip to content

Commit

Permalink
Fix for Vercal “unsupported modules” error
Browse files Browse the repository at this point in the history
  • Loading branch information
jhildenbiddle committed Dec 21, 2023
1 parent 28c6b62 commit 65b30fe
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 34 deletions.
4 changes: 2 additions & 2 deletions jest.config.js
@@ -1,6 +1,6 @@
import serverConfig from './server.config.js';
import serverConfigs from './server.configs.js';

const { hostname, port } = serverConfig.test;
const { hostname, port } = serverConfigs.test;
const TEST_HOST = `http://${hostname}:${port}`;
const sharedConfig = {
errorOnDeprecated: true,
Expand Down
4 changes: 3 additions & 1 deletion middleware.js
@@ -1,4 +1,6 @@
import { rewriteRules } from './server.config.js';
import serverConfigs from './server.configs.js';

const { rewriteRules } = serverConfigs.dev;

// Exports
// =============================================================================
Expand Down
4 changes: 2 additions & 2 deletions playwright.config.js
@@ -1,7 +1,7 @@
import { devices } from '@playwright/test';
import serverConfig from './server.config.js';
import serverConfigs from './server.configs.js';

const { hostname, port } = serverConfig.test;
const { hostname, port } = serverConfigs.test;
const TEST_HOST = `http://${hostname}:${port}`;

process.env.TEST_HOST = TEST_HOST;
Expand Down
49 changes: 23 additions & 26 deletions server.config.js → server.configs.js
Expand Up @@ -4,31 +4,6 @@ import * as url from 'node:url';
const __filename = url.fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// Rewrite rules shared with Vercel middleware.js
export const rewriteRules = [
// Replace CDN URLs with local paths
{
match: /https?.*\/CHANGELOG.md/g,
replace: '/CHANGELOG.md',
},
{
// CDN versioned default
// Ex1: //cdn.com/package-name
// Ex2: http://cdn.com/package-name@1.0.0
// Ex3: https://cdn.com/package-name@latest
match: /(?:https?:)*\/\/.*cdn.*docsify[@\d.latest]*(?=["'])/g,
replace: '/lib/docsify.min.js',
},
{
// CDN paths to local paths
// Ex1: //cdn.com/package-name/path/file.js => /path/file.js
// Ex2: http://cdn.com/package-name@1.0.0/dist/file.js => /dist/file.js
// Ex3: https://cdn.com/package-name@latest/dist/file.js => /dist/file.js
match: /(?:https?:)*\/\/.*cdn.*docsify[@\d.latest]*\/(?:lib\/)/g,
replace: '/lib/',
},
];

// Production (CDN URLs, watch disabled)
const prod = {
hostname: '127.0.0.1',
Expand All @@ -47,7 +22,29 @@ const dev = {
...prod,
files: ['CHANGELOG.md', 'docs/**/*', 'lib/**/*'],
port: 3000,
rewriteRules,
rewriteRules: [
// Replace CDN URLs with local paths
{
match: /https?.*\/CHANGELOG.md/g,
replace: '/CHANGELOG.md',
},
{
// CDN versioned default
// Ex1: //cdn.com/package-name
// Ex2: http://cdn.com/package-name@1.0.0
// Ex3: https://cdn.com/package-name@latest
match: /(?:https?:)*\/\/.*cdn.*docsify[@\d.latest]*(?=["'])/g,
replace: '/lib/docsify.min.js',
},
{
// CDN paths to local paths
// Ex1: //cdn.com/package-name/path/file.js => /path/file.js
// Ex2: http://cdn.com/package-name@1.0.0/dist/file.js => /dist/file.js
// Ex3: https://cdn.com/package-name@latest/dist/file.js => /dist/file.js
match: /(?:https?:)*\/\/.*cdn.*docsify[@\d.latest]*\/(?:lib\/)/g,
replace: '/lib/',
},
],
server: {
...prod.server,
routes: {
Expand Down
2 changes: 1 addition & 1 deletion server.js
@@ -1,5 +1,5 @@
import { create } from 'browser-sync';
import serverConfigs from './server.config.js';
import serverConfigs from './server.configs.js';

const bsServer = create();
const args = process.argv.slice(2);
Expand Down
4 changes: 2 additions & 2 deletions test/config/server.js
@@ -1,13 +1,13 @@
import * as process from 'node:process';
import { create } from 'browser-sync';
import config from '../../server.config.js';
import serverConfigs from '../../server.configs.js';

const bsServer = create();

export async function startServer() {
// Wait for server to start
return new Promise(resolve => {
const settings = config.test;
const settings = serverConfigs.test;

console.log('\n');

Expand Down

0 comments on commit 65b30fe

Please sign in to comment.