Skip to content
This repository was archived by the owner on Feb 11, 2022. It is now read-only.

Commit 23ef40d

Browse files
committed
fix(antwar): Disable interactive output caching
That's too unreliable. Better skip.
1 parent df1aac4 commit 23ef40d

File tree

1 file changed

+105
-109
lines changed

1 file changed

+105
-109
lines changed

packages/antwar/src/build/worker.js

+105-109
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ function processPage(
8888
}
8989
});
9090

91-
// Calculate hash based on filename and section so we can check whether
92-
// to generate a bundle at all. Use a relative path so the project directory
93-
// can be moved around.
91+
// Calculate hash based on filename and section to avoid ENAMETOOLONG.
92+
// TODO: See if this check could be skipped entirely.
9493
const filename = calculateMd5(
9594
_path
9695
.relative(cwd, path)
@@ -104,125 +103,122 @@ function processPage(
104103
// Attach generated file to template
105104
jsFiles.push(`/${filename}.js`);
106105

107-
// If the bundle exists already, skip generating
108-
if (!_fs.existsSync(interactivePath)) {
109-
const interactiveIndexEntry = ejs.compile(
110-
templates.interactiveIndex.file
111-
)({
112-
components,
113-
});
114-
const entry = ejs.compile(templates.interactive.file)({
115-
components,
116-
});
117-
118-
// Touch output so that other processes get a clue
119-
touch.sync(interactivePath);
120-
121-
// Write to a temporary files so we can point webpack to that
122-
const interactiveEntryTmpFile = tmp.fileSync();
123-
const entryTmpFile = tmp.fileSync();
106+
const interactiveIndexEntry = ejs.compile(
107+
templates.interactiveIndex.file
108+
)({
109+
components,
110+
});
111+
const entry = ejs.compile(templates.interactive.file)({
112+
components,
113+
});
124114

125-
// XXX: convert to async
126-
_fs.writeFileSync(interactiveEntryTmpFile.name, interactiveIndexEntry);
127-
_fs.writeFileSync(entryTmpFile.name, entry);
115+
// Touch output so that other processes get a clue
116+
touch.sync(interactivePath);
128117

129-
const interactiveConfig = require(configurationPaths.webpack)(
130-
"interactive"
131-
);
132-
const webpackConfig = merge(interactiveConfig, {
133-
mode: "production",
134-
resolve: {
135-
modules: [cwd, _path.join(cwd, "node_modules")],
136-
alias: generateAliases(components),
137-
},
138-
resolveLoader: {
139-
modules: [cwd, _path.join(cwd, "node_modules")],
140-
},
141-
});
118+
// Write to a temporary files so we can point webpack to that
119+
const interactiveEntryTmpFile = tmp.fileSync();
120+
const entryTmpFile = tmp.fileSync();
142121

143-
const interactiveIndexEntryName = `${filename}-interactive-entry`;
122+
// XXX: convert to async
123+
_fs.writeFileSync(interactiveEntryTmpFile.name, interactiveIndexEntry);
124+
_fs.writeFileSync(entryTmpFile.name, entry);
144125

145-
// Override webpack configuration to process correctly
146-
webpackConfig.entry = {
147-
[interactiveIndexEntryName]: interactiveEntryTmpFile.name,
148-
[filename]: entryTmpFile.name,
149-
};
126+
const interactiveConfig = require(configurationPaths.webpack)(
127+
"interactive"
128+
);
129+
const webpackConfig = merge(interactiveConfig, {
130+
mode: "production",
131+
resolve: {
132+
modules: [cwd, _path.join(cwd, "node_modules")],
133+
alias: generateAliases(components),
134+
},
135+
resolveLoader: {
136+
modules: [cwd, _path.join(cwd, "node_modules")],
137+
},
138+
});
150139

151-
// Merge output to avoid overriding publicPath
152-
webpackConfig.output = merge(interactiveConfig.output, {
153-
filename: "[name].js",
154-
path: outputPath,
155-
publicPath: "/",
156-
libraryTarget: "umd", // Needed for interactive index exports to work
157-
globalObject: "this",
158-
});
140+
const interactiveIndexEntryName = `${filename}-interactive-entry`;
141+
142+
// Override webpack configuration to process correctly
143+
webpackConfig.entry = {
144+
[interactiveIndexEntryName]: interactiveEntryTmpFile.name,
145+
[filename]: entryTmpFile.name,
146+
};
147+
148+
// Merge output to avoid overriding publicPath
149+
webpackConfig.output = merge(interactiveConfig.output, {
150+
filename: "[name].js",
151+
path: outputPath,
152+
publicPath: "/",
153+
libraryTarget: "umd", // Needed for interactive index exports to work
154+
globalObject: "this",
155+
});
159156

160-
return webpack(webpackConfig, (err2, stats) => {
161-
if (err2) {
162-
return cb(err2);
163-
}
157+
return webpack(webpackConfig, (err2, stats) => {
158+
if (err2) {
159+
return cb(err2);
160+
}
164161

165-
if (stats.hasErrors()) {
166-
return cb(stats.toString("errors-only"));
167-
}
162+
if (stats.hasErrors()) {
163+
return cb(stats.toString("errors-only"));
164+
}
168165

169-
const assets = stats.compilation.assets;
170-
const cssFiles = Object.keys(assets)
171-
.map(asset => {
172-
if (_path.extname(asset) === ".css") {
173-
return assets[asset].existsAt;
174-
}
175-
176-
return null;
177-
})
178-
.filter(a => a)
179-
.map(cssFile => "/" + _path.basename(cssFile));
180-
181-
const interactiveIndexPath = _path.join(
182-
outputPath,
183-
interactiveIndexEntryName
184-
);
185-
const interactiveComponents = require(interactiveIndexPath);
186-
const renderErrors = [];
187-
188-
// Render initial HTML for each component
189-
$(".interactive").each((i, el) => {
190-
const $el = $(el);
191-
const props = $el.data("props");
192-
193-
try {
194-
$el.html(
195-
antwarConfiguration.render.interactive({
196-
component: interactiveComponents[`Interactive${i}`],
197-
props,
198-
})
199-
);
200-
} catch (renderErr) {
201-
renderErrors.push(renderErr);
166+
const assets = stats.compilation.assets;
167+
const cssFiles = Object.keys(assets)
168+
.map(asset => {
169+
if (_path.extname(asset) === ".css") {
170+
return assets[asset].existsAt;
202171
}
203-
});
204172

205-
if (renderErrors.length) {
206-
return cb(renderErrors[0]);
173+
return null;
174+
})
175+
.filter(a => a)
176+
.map(cssFile => "/" + _path.basename(cssFile));
177+
178+
const interactiveIndexPath = _path.join(
179+
outputPath,
180+
interactiveIndexEntryName
181+
);
182+
const interactiveComponents = require(interactiveIndexPath);
183+
const renderErrors = [];
184+
185+
// Render initial HTML for each component
186+
$(".interactive").each((i, el) => {
187+
const $el = $(el);
188+
const props = $el.data("props");
189+
190+
try {
191+
$el.html(
192+
antwarConfiguration.render.interactive({
193+
component: interactiveComponents[`Interactive${i}`],
194+
props,
195+
})
196+
);
197+
} catch (renderErr) {
198+
renderErrors.push(renderErr);
207199
}
200+
});
201+
202+
if (renderErrors.length) {
203+
return cb(renderErrors[0]);
204+
}
208205

209-
rimraf.sync(interactiveIndexPath + ".*");
210-
211-
// Wrote a bundle, compile through ejs now
212-
const data = ejs.compile(templates.page.file)({
213-
context: {
214-
...context,
215-
...page.file,
216-
...templates.page,
217-
cssFiles: [...templates.page.cssFiles, ...cssFiles],
218-
jsFiles: [...templates.page.jsFiles, ...jsFiles],
219-
html: $.html(),
220-
},
221-
});
222-
223-
return writePage({ console, path, data, page }, cb);
206+
rimraf.sync(interactiveIndexPath + ".*");
207+
208+
// Wrote a bundle, compile through ejs now
209+
const data = ejs.compile(templates.page.file)({
210+
context: {
211+
...context,
212+
...page.file,
213+
...templates.page,
214+
cssFiles: [...templates.page.cssFiles, ...cssFiles],
215+
jsFiles: [...templates.page.jsFiles, ...jsFiles],
216+
html: $.html(),
217+
},
224218
});
225-
}
219+
220+
return writePage({ console, path, data, page }, cb);
221+
});
226222
}
227223

228224
// No need to go through webpack so go only through ejs

0 commit comments

Comments
 (0)