Skip to content

Commit

Permalink
Merge pull request #230 from vstefanovic97/master
Browse files Browse the repository at this point in the history
Bump content-tag and add inline_source_map option
  • Loading branch information
NullVoxPopuli authored Feb 1, 2024
2 parents b70b8a5 + d827f8d commit 83d707d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,20 @@ module('Integration | Component | hello', function (hooks) {

```

## Sourcemap Generation

This can be useful for development and test purposes, it should be disabled for production

```js
// ember-cli-build.js
module.exports = function (defaults) {
let app = new EmberAddon(defaults, {
'ember-template-imports': {
inline_source_map: true
}
});
```
## Reference: built-in helpers, modifiers, components
As implemented as part of the [Strict Mode Templates RFC][rfc-496], the built in
Expand Down
14 changes: 13 additions & 1 deletion ember-addon-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,19 @@ module.exports = {
setupPreprocessorRegistry(type, registry) {
if (type === 'parent') {
let TemplateImportPreprocessor = require('./src/preprocessor-plugin');
registry.add('js', new TemplateImportPreprocessor());
registry.add(
'js',
new TemplateImportPreprocessor(this._getAddonOptions()),
);
}
},

_getAddonOptions() {
let parentOptions = this.parent && this.parent.options;
let appOptions = this.app && this.app.options;

const options = parentOptions || appOptions || {};

return options['ember-template-imports'] || { inline_source_map: false };
},
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"dependencies": {
"broccoli-stew": "^3.0.0",
"content-tag": "^1.1.2",
"content-tag": "^2.0.1",
"ember-cli-version-checker": "^5.1.2"
},
"devDependencies": {
Expand Down
13 changes: 9 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions src/preprocessor-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ const { Preprocessor } = require('content-tag');

module.exports = class TemplateImportPreprocessor {
#processor;
#inline_source_map;

constructor() {
constructor({ inline_source_map = false }) {
this.name = 'template-imports-preprocessor';
this.#inline_source_map = inline_source_map;
this.#processor = new Preprocessor();
}

toTree(tree) {
let compiled = stew.map(tree, `**/*.{gjs,gts}`, (string, relativePath) => {
let transformed = this.#processor.process(string, relativePath);
let transformed = this.#processor.process(string, {
filename: relativePath,
inline_source_map: this.#inline_source_map,
});

return transformed;
});
Expand Down

0 comments on commit 83d707d

Please sign in to comment.