Skip to content

Commit

Permalink
Return TransformedSource in process()
Browse files Browse the repository at this point in the history
  • Loading branch information
3c1u committed Apr 30, 2022
1 parent fd7c965 commit 7fade65
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ module.exports = {
(typeof transformConfig.config.modules === "function" &&
transformConfig.config.modules(filename)));
if (!useModules) {
return stripIndent`
const styleInject = require('style-inject');
return {
code: stripIndent`
const styleInject = require('style-inject');
styleInject(${JSON.stringify(src)});
module.exports = {};
`;
styleInject(${JSON.stringify(src)});
module.exports = {};
`,
};
}

// The "process" function of this Jest transform must be sync,
Expand Down Expand Up @@ -101,18 +103,22 @@ module.exports = {
// we forward the logs and return no mappings
console.error(result.stderr.toString());
console.log(result.stdout.toString());
return stripIndent`
console.error("transform-css: Failed to load '${filename}'");
module.exports = {};
`;
return {
code: stripIndent`
console.error("transform-css: Failed to load '${filename}'");
module.exports = {};
`,
};
}

// Finally, inject the styles to the document
return stripIndent`
const styleInject = require('style-inject');
return {
code: stripIndent`
const styleInject = require('style-inject');
styleInject(${JSON.stringify(css)});
module.exports = ${JSON.stringify(tokens)};
`;
styleInject(${JSON.stringify(css)});
module.exports = ${JSON.stringify(tokens)};
`,
};
},
};

0 comments on commit 7fade65

Please sign in to comment.