Skip to content

Commit

Permalink
CoffeeScript cache depend on compilation settings (fix #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
edemaine committed Apr 7, 2022
1 parent 27e5a4c commit 26ab529
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ client/main.tsx on server using Solid with Babel preset ["solid",{"generate":"ss

Note that the CoffeeScript compiler caches compilation results on disk,
so you won't see how `.coffee` files got compiled on subsequent startup
until you modify those files again.
until you modify those files (or change settings) again.
Alternatively, you can reset the cache by deleting the directory
`.meteor/local/plugin-cache/edemaine_solid` and restarting Meteor.

## Alternatives

Expand Down
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'edemaine:solid',
version: '0.2.2',
version: '0.2.3',
summary: 'Compiler plugin for SolidJS including SSR',
documentation: 'README.md',
git: 'https://github.com/edemaine/meteor-solid.git',
Expand Down
40 changes: 27 additions & 13 deletions plugin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const solidOptionsCache = {};
function modifyBabelConfig(babelOptions, inputFile) {
const client = babelOptions.caller.arch.startsWith('web');

function getSolidConfig(inputFile) {
const isClient = inputFile.getArch().startsWith('web');

let solidOptions = {};
// Read package.json, based on _inferFromPackageJson in
Expand Down Expand Up @@ -43,23 +44,33 @@ function modifyBabelConfig(babelOptions, inputFile) {
useSolid = useSolid && !Npm.require('micromatch').isMatch(
inputFile.getPathInPackage(), solidOptions.ignore);

// Modify babelOptions in-place.
// Compute Solid preset
let solidPreset = null;
if (useSolid) {
if (!babelOptions.presets)
babelOptions.presets = [];
if (solidOptions.ssr) {
const hydratable = solidOptions.hydratable !== false;
if (client)
babelOptions.presets.push(solidPreset =
["solid", {generate: "dom", hydratable}]);
if (isClient)
solidPreset = ["solid", {generate: "dom", hydratable}];
else // server
babelOptions.presets.push(solidPreset =
["solid", {generate: "ssr", hydratable}]);
solidPreset = ["solid", {generate: "ssr", hydratable}];
} else {
if (client)
babelOptions.presets.push(solidPreset = ["solid"]);
if (isClient)
solidPreset = ["solid"];
}
}

return {solidOptions, isClient, useSolid, solidPreset};
}

function modifyBabelConfig(babelOptions, inputFile) {
const {solidOptions, isClient, useSolid, solidPreset} =
getSolidConfig(inputFile);

// Modify babelOptions in-place.
if (solidPreset) {
if (!babelOptions.presets)
babelOptions.presets = [];
babelOptions.presets.push(solidPreset);
} else {
// Fall back to React mode, Meteor's default.
// Modify Meteor's options which are in a bundle as the first preset.
Expand All @@ -85,7 +96,7 @@ function modifyBabelConfig(babelOptions, inputFile) {
console.log(inputFile.getPathInPackage() +
(inputFile.getPackageName() ?
` in package ${inputFile.getPackageName()}` : ''),
`on ${client ? 'client' : 'server'}`,
`on ${isClient ? 'client' : 'server'}`,
`using ${useSolid ? 'Solid' : 'React'}` +
(useSolid ? ` with Babel preset ${JSON.stringify(solidPreset)}` : ''));
}
Expand Down Expand Up @@ -149,11 +160,14 @@ if (Package['coffeescript-compiler']) {
}

getCacheKey(inputFile) {
const {useSolid, solidPreset} = getSolidConfig(inputFile);
return [
inputFile.getArch(),
inputFile.getSourceHash(),
inputFile.getDeclaredExports(),
this.coffeeScriptCompiler.getCompileOptions(inputFile),
useSolid,
solidPreset,
];
}

Expand Down

0 comments on commit 26ab529

Please sign in to comment.