refactor code to exclude coffeescript from automatic installation and config

This commit is contained in:
Nacho Codoñer
2025-08-20 17:49:57 +02:00
parent 5694a4c62a
commit 678812ae10
11 changed files with 48 additions and 118 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "@meteorjs/rspack",
"version": "0.0.30",
"version": "0.0.31",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@meteorjs/rspack",
"version": "0.0.30",
"version": "0.0.31",
"license": "ISC",
"dependencies": {
"ignore-loader": "^0.1.2",

View File

@@ -1,6 +1,6 @@
{
"name": "@meteorjs/rspack",
"version": "0.0.30",
"version": "0.0.31",
"description": "Configuration logic for using Rspack in Meteor projects",
"main": "index.js",
"type": "module",

View File

@@ -82,21 +82,6 @@ function createSwcConfig({
};
}
// Coffeescript rule
function createCoffeescriptConfig({ swcConfig }) {
return {
test: /\.coffee$/i,
use: [
{
loader: 'swc-loader',
options: swcConfig,
},
{
loader: 'coffee-loader',
},
],
};
}
// Keep files outside of build folders
function keepOutsideBuild() {
@@ -148,7 +133,6 @@ export default function (inMeteor = {}, argv = {}) {
const isTsxEnabled =
Meteor.isTsxEnabled || (isTypescriptEnabled && isReactEnabled) || false;
const isCoffeescriptEnabled = Meteor.isCoffeescriptEnabled || false;
// Determine entry points
const entryPath = Meteor.entryPath;
@@ -227,6 +211,9 @@ export default function (inMeteor = {}, argv = {}) {
externalHelpers: swcExternalHelpers,
isDevEnvironment,
});
// Expose swc config to use in custom configs
Meteor.swcConfigOptions = swcConfigRule.options;
const externals = [
/^meteor.*/,
...(isReactEnabled ? [/^react$/, /^react-dom$/] : []),
@@ -235,7 +222,6 @@ export default function (inMeteor = {}, argv = {}) {
'/': path.resolve(process.cwd()),
};
const extensions = [
...(isCoffeescriptEnabled ? ['.coffee'] : []),
'.ts',
'.tsx',
'.mts',
@@ -247,11 +233,7 @@ export default function (inMeteor = {}, argv = {}) {
'.json',
'.wasm',
];
const extraRules = [
...(isCoffeescriptEnabled
? [createCoffeescriptConfig({ swcConfig: swcConfigRule?.options })]
: []),
];
const extraRules = [];
const reactRefreshModule = isReactEnabled
? safeRequire('@rspack/plugin-react-refresh')

View File

@@ -52,7 +52,6 @@ function getFileExtensionsToIgnore() {
// Base extensions to ignore
const baseExtensions = [
'.coffee',
'.ts',
'.tsx',
'.js',

View File

@@ -5,13 +5,10 @@
export const DEFAULT_RSPACK_VERSION = '1.4.8';
export const DEFAULT_METEOR_RSPACK_VERSION = '0.0.30';
export const DEFAULT_METEOR_RSPACK_VERSION = '0.0.31';
export const DEFAULT_METEOR_RSPACK_REACT_HMR_VERSION = '1.4.3';
export const DEFAULT_METEOR_RSPACK_COFFEESCRIPT_VERSION = '2.7.0';
export const DEFAULT_METEOR_RSPACK_COFFEE_LOADER_VERSION = '5.0.0';
export const DEFAULT_METEOR_RSPACK_SWC_LOADER_VERSION = '0.2.6';
@@ -33,8 +30,6 @@ export const GLOBAL_STATE_KEYS = {
SERVER_PROCESS: 'rspack.serverProcess',
RSPACK_INSTALLATION_CHECKED: 'rspack.rspackInstallationChecked',
RSPACK_REACT_INSTALLATION_CHECKED: 'rspack.rspackReactInstallationChecked',
COFFEESCRIPT_CHECKED: 'rspack.coffeescriptChecked',
RSPACK_COFFEESCRIPT_INSTALLATION_CHECKED: 'rspack.rspackCoffeescriptInstallationChecked',
REACT_CHECKED: 'rspack.reactChecked',
INITIAL_ENTRYPONTS: 'meteor.initialEntrypoints',
CLIENT_FIRST_COMPILE: 'rspack.clientFirstCompile',

View File

@@ -16,7 +16,6 @@ const {
} = require('meteor/tools-core/lib/log');
const {
getMeteorAppDir,
isMeteorCoffeescriptProject,
} = require('meteor/tools-core/lib/meteor');
const {
checkNpmDependencyExists,
@@ -31,8 +30,6 @@ const {
DEFAULT_RSPACK_VERSION,
DEFAULT_METEOR_RSPACK_VERSION,
DEFAULT_METEOR_RSPACK_REACT_HMR_VERSION,
DEFAULT_METEOR_RSPACK_COFFEESCRIPT_VERSION,
DEFAULT_METEOR_RSPACK_COFFEE_LOADER_VERSION,
DEFAULT_METEOR_RSPACK_SWC_LOADER_VERSION,
GLOBAL_STATE_KEYS,
} = require('./constants');
@@ -180,46 +177,3 @@ export async function ensureRspackReactInstalled() {
'Rspack React'
);
}
/**
* Checks if Coffeescript is installed and sets global state accordingly
* Sets global state and environment variables based on Coffeescript detection
* @returns {Promise<void>} A promise that resolves when the check is complete
*/
export function checkCoffeescriptInstalled() {
// Skip if already checked
if (getGlobalState(GLOBAL_STATE_KEYS.COFFEESCRIPT_CHECKED, false)) {
return;
}
const appDir = getMeteorAppDir();
const isCoffescriptInstalled =
checkNpmDependencyExists('coffeescript', { cwd: appDir }) ||
isMeteorCoffeescriptProject();
if (isCoffescriptInstalled) {
// Set environment variable to indicate React is enabled
process.env.METEOR_COFFEESCRIPT_ENABLED = 'true';
} else {
process.env.METEOR_COFFEESCRIPT_ENABLED = 'false';
}
// Mark as checked
setGlobalState(GLOBAL_STATE_KEYS.COFFEESCRIPT_CHECKED, true);
return isCoffescriptInstalled;
}
export async function ensureRspackCoffeescriptInstalled() {
const dependencies = [
{ name: 'coffeescript', version: DEFAULT_METEOR_RSPACK_COFFEESCRIPT_VERSION, semverCondition: 'gte', dev: true },
{ name: 'coffee-loader', version: DEFAULT_METEOR_RSPACK_COFFEE_LOADER_VERSION, semverCondition: 'gte', dev: true },
{ name: 'swc-loader', version: DEFAULT_METEOR_RSPACK_SWC_LOADER_VERSION, semverCondition: 'gte', dev: true }
];
await ensureDependenciesInstalled(
dependencies,
GLOBAL_STATE_KEYS.RSPACK_COFFEESCRIPT_INSTALLATION_CHECKED,
'Rspack Coffeescript'
);
}

View File

@@ -93,7 +93,6 @@ export function getRspackEnv({ isClient, isServer, isTest: inIsTest }) {
const isJsxEnabled = inputFilePath?.endsWith('.jsx');
const isReactEnabled = !!process.env.METEOR_REACT_ENABLED;
const isCoffeescriptEnabled = !!process.env.METEOR_COFFEESCRIPT_ENABLED;
const isBlazeEnabled = isMeteorBlazeProject();
const isBlazeHotEnabled = isMeteorBlazeHotProject();
@@ -136,7 +135,6 @@ export function getRspackEnv({ isClient, isServer, isTest: inIsTest }) {
...(isTypescriptEnabled && [['isTypescriptEnabled', isTypescriptEnabled]] || []),
...(isTsxEnabled && [['isTsxEnabled', isTsxEnabled]] || []),
...(isJsxEnabled && [['isJsxEnabled', isJsxEnabled]] || []),
...(isCoffeescriptEnabled && [['isCoffeescriptEnabled', isCoffeescriptEnabled]] || []),
].filter(Boolean);
return pairs.flatMap(([key, val]) => [
'--env',

View File

@@ -23,8 +23,6 @@ const {
ensureRspackInstalled,
checkReactInstalled,
ensureRspackReactInstalled,
checkCoffeescriptInstalled,
ensureRspackCoffeescriptInstalled,
} = require('./lib/dependencies');
const {
@@ -81,9 +79,6 @@ try {
await ensureRspackReactInstalled();
}
if (checkCoffeescriptInstalled()) {
await ensureRspackCoffeescriptInstalled();
}
// Ensure the Rspack build context directory exists
ensureRspackBuildContextExists();

View File

@@ -10,13 +10,15 @@
"dependencies": {
"@babel/runtime": "^7.23.5",
"@swc/helpers": "^0.5.17",
"coffeescript": "^2.7.0",
"meteor-node-stubs": "^1.2.12",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"playwright": "^1.54.2"
"playwright": "^1.54.2",
"coffee-loader": "^5.0.0",
"coffeescript": "^2.7.0",
"swc-loader": "^0.2.6"
},
"meteor": {
"mainModule": {

View File

@@ -0,0 +1,36 @@
import { defineConfig } from '@meteorjs/rspack';
/**
* Rspack configuration for Meteor projects.
*
* Provides typed flags on the `Meteor` object, such as:
* - `Meteor.isClient` / `Meteor.isServer`
* - `Meteor.isDevelopment` / `Meteor.isProduction`
* - …and other flags available
*
* Use these flags to adjust your build settings based on environment.
*/
export default defineConfig(Meteor => {
return {
module: {
rules: [
{
test: /\.coffee$/i,
use: [
{
loader: 'swc-loader',
// perserve SWC config in the Meteor project level
options: Meteor.swcConfigOptions,
},
{
loader: 'coffee-loader',
},
],
},
],
},
resolve: {
extensions: ['.coffee'],
},
};
});

View File

@@ -20,45 +20,14 @@ describe('CoffeeScript App Bundling /', () => {
test: (message) => `console.log "${message}"`
},
customAssertions: {
afterRun: async ({ result }) => {
await waitForCoffeescriptEnvs(result.outputLines);
},
afterRunRebuildClient: async ({ allConsoleLogs }) => {
// Check for HMR output as enabled by default
await waitForMeteorOutput(allConsoleLogs, /.*HMR.*Updated modules:.*/);
},
afterRunProduction: async ({ result }) => {
await waitForCoffeescriptEnvs(result.outputLines);
},
afterRunProductionRebuildClient: async ({ allConsoleLogs }) => {
// Check for HMR to not be enabled in production-like mode
await waitForMeteorOutput(allConsoleLogs, /.*HMR.*Updated modules:*/, { negate: true });
},
afterTest: async ({ result }) => {
await waitForCoffeescriptEnvs(result.outputLines);
},
afterTestOnce: async ({ result }) => {
await waitForCoffeescriptEnvs(result.outputLines);
},
afterBuild: async ({ result }) => {
await waitForCoffeescriptEnvs(result.outputLines);
},
}
}));
});
/**
* Helper function to wait for CoffeeScript environment output from both Rspack Client and Server
* @param {string[]} outputLines - Array that will be populated with output lines
* @param {Object} options - Options for waiting
* @param {number} options.timeout - Maximum time to wait in milliseconds
* @param {number} options.checkInterval - Interval between checks in milliseconds
* @returns {Promise<void>} - A promise that resolves when coffeescript envs are enabled
*/
export async function waitForCoffeescriptEnvs(outputLines, options = {}) {
await waitForMeteorOutput(
outputLines,
/.*isCoffeescriptEnabled:.*true.*/,
options
);
}