Skip to content

Commit

Permalink
Merge pull request #910 from thoov/preprocess-argument-fix
Browse files Browse the repository at this point in the history
Fix arguments to `preprocessCss` (to match classic build)
  • Loading branch information
rwjblue authored Jul 30, 2021
2 parents 7165f06 + 5083212 commit 034763b
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/compat/src/v1-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ export default class V1App {
};

let nestedInput = buildFunnel(this.combinedStyles(addonTrees), { destDir: 'app/styles' });
let styles = this.preprocessors.preprocessCss(nestedInput, 'app/styles', '/assets', options);
let styles = this.preprocessors.preprocessCss(nestedInput, '/app/styles', '/assets', options);

return new AddToTree(styles, outputPath => {
let addonMeta: AddonMeta = {
Expand Down
46 changes: 46 additions & 0 deletions tests/fixtures/preprocess-addon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

const Filter = require('broccoli-persistent-filter');
const funnel = require('broccoli-funnel');
const { join } = require('path').posix;

class Awk extends Filter {
constructor(inputNode, searchReplaceObj) {
super(inputNode, {});
this.searchReplaceObj = searchReplaceObj;
}

processString(content) {
let modifiedContent = content;

Object.entries(this.searchReplaceObj).forEach(([search, replace]) => {
modifiedContent = modifiedContent.replace(search, replace);
});

return modifiedContent;
}
}

module.exports = {
name: require('./package').name,

setupPreprocessorRegistry(type, registry) {
registry.add('css', {
name: this.name,
ext: 'css',
toTree: (tree, inputPath, outputPath) => {
return funnel(new Awk(tree, { '%%%': inputPath === '/app/styles' ? 'red' : 'blue' }), {
getDestinationPath(relativePath) {
let relativePathWithPrefix = `/${relativePath}`;

if (relativePathWithPrefix === `${inputPath}/app.css`) {
return join(outputPath, 'app-template.css');
}

return join(outputPath, relativePathWithPrefix.replace(inputPath, ''));
},
});
},
});
},
};
17 changes: 10 additions & 7 deletions tests/scenarios/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,30 @@
"bootstrap": "^4.3.1",
"broccoli-funnel": "^3.0.5",
"broccoli-merge-trees": "^3.0.2",
"broccoli-persistent-filter": "^3.1.2",
"ember-bootstrap": "^4.6.3",
"ember-cli-latest": "npm:ember-cli@latest",
"ember-cli-beta": "npm:ember-cli@beta",
"ember-cli-3.16": "npm:ember-cli@~3.16.0",
"ember-cli-3.20": "npm:ember-cli@~3.20.0",
"ember-cli-3.24": "npm:ember-cli@~3.24.0",
"ember-cli-beta": "npm:ember-cli@beta",
"ember-cli-latest": "npm:ember-cli@latest",
"ember-cli-fastboot": "^2.2.3",
"ember-composable-helpers": "^4.4.1",
"ember-data-3.16": "npm:ember-data@~3.16.0",
"ember-data-3.20": "npm:ember-data@~3.20.0",
"ember-data-3.24": "npm:ember-data@~3.24.0",
"ember-data-latest": "npm:ember-data@latest",
"ember-engines": "^0.8.16",
"ember-inline-svg": "^0.2.1",
"ember-source-latest": "npm:ember-source@latest",
"ember-source-beta": "npm:ember-source@beta",
"ember-source-3.16": "npm:ember-source@~3.16.0",
"ember-source-3.20": "npm:ember-source@~3.20.0",
"ember-source-3.24": "npm:ember-source@~3.24.0",
"fastboot-addon": "link:../../test-packages/fastboot-addon",
"ember-engines": "^0.8.16",
"ember-inline-svg": "^0.2.1",
"ember-composable-helpers": "^4.4.1",
"ember-truth-helpers": "^3.0.0"
"ember-source-beta": "npm:ember-source@beta",
"ember-source-latest": "npm:ember-source@latest",
"ember-truth-helpers": "^3.0.0",
"fastboot-addon": "link:../../test-packages/fastboot-addon"
},
"volta": {
"node": "14.16.1",
Expand Down
40 changes: 40 additions & 0 deletions tests/scenarios/preprocess-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { appScenarios } from './scenarios';
import { PreparedApp, Project } from 'scenario-tester';
import QUnit from 'qunit';
import merge from 'lodash/merge';
import { loadFromFixtureData } from './helpers';
import { dirname, join } from 'path';
import fs from 'fs';
const { module: Qmodule, test } = QUnit;

appScenarios
.map('preprocess', project => {
let preprocessAddon = Project.fromDir(dirname(require.resolve('../addon-template/package.json')), {
linkDeps: true,
});

merge(preprocessAddon.files, loadFromFixtureData('preprocess-addon'));
preprocessAddon.linkDependency('broccoli-funnel', { baseDir: __dirname });
preprocessAddon.linkDependency('broccoli-persistent-filter', { baseDir: __dirname });
preprocessAddon.pkg.name = 'preprocess-addon';

project.addDevDependency(preprocessAddon);
merge(project.files, {
app: {
styles: {
'app.css': `body { background: %%%; }`,
},
},
});
})
.forEachScenario(scenario => {
Qmodule(scenario.name, function () {
test(`yarn test`, async function (assert) {
let app: PreparedApp = await scenario.prepare();
await app.execute('node ./node_modules/ember-cli/bin/ember b');

const data = fs.readFileSync(join(app.dir, 'dist', 'assets', 'app-template.css'), 'utf8');
assert.equal(data, 'body { background: red; }');
});
});
});

0 comments on commit 034763b

Please sign in to comment.