Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielAmenou-R2net committed Nov 30, 2022
1 parent 401c976 commit 68d3a7a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const PLUGIN_NAME = "rollup-plugin-lib-style"
const MAGIC_PATH_REGEX = /@@_MAGIC_PATH_@@/g
const MAGIC_PATH = "@@_MAGIC_PATH_@@"

const modulesIds = new Set()
const emittedCssFiles = []

const outputPaths = []

Expand Down Expand Up @@ -41,12 +41,16 @@ const libStylePlugin = (options = {}) => {
else options.output.forEach((outputOptions) => outputPaths.push(outputOptions.dir))
},

resolveId(source) {
console.log("source", source)
if (emittedCssFiles.some((currentFileId) => source.replace(process.cwd(), "").replace(/\\/g, "/").includes(currentFileId))) return {id: "./file1.js"}
},

async transform(code, id) {
const loader = getLoader(id)
if (!filter(id) || !loader) return null

modulesIds.add(id)

//console.log("emittedCssFiles", id.replace(process.cwd(), "").replace(/\\/g, "/"), emittedCssFiles)
const rawCss = await loader.process({filePath: id, code})

const postCssResult = await postCssTransformer({code: rawCss.code, fiePath: id, options: postCssOptions})
Expand All @@ -56,13 +60,16 @@ const libStylePlugin = (options = {}) => {
const cssFilePath = id.replace(process.cwd(), "").replace(/\\/g, "/")

// create a new css file with the generated hash class names
const newCssFileName = cssFilePath.replace("/", "").replace(loader.regex, ".css")
emittedCssFiles.push(newCssFileName)

this.emitFile({
type: "asset",
fileName: cssFilePath.replace("/", "").replace(loader.regex, ".css"),
source: postCssResult.extracted.code,
})

const importStr = importCSS ? `import "${MAGIC_PATH}${cssFilePath.replace(loader.regex, ".css")}";\n` : ""
const importStr = importCSS ? `import ".${cssFilePath.replace(loader.regex, ".css")}";\n` : ""

// create a new js file with css module
return {
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ describe("plugin options", () => {
const file1 = fs.readFileSync(path.join(TESTS_OUTPUT_DIR, "..", "..", "file1.js")).toString()
expect(file1).toContain("{\"test1\":\"test1\"")
})
})
})
2 changes: 1 addition & 1 deletion test/test_files/styles1.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

.test4 {
justify-content: center;
}
}

0 comments on commit 68d3a7a

Please sign in to comment.