Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/v0.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
occar421 committed Apr 1, 2018
2 parents 923ff30 + dd6be59 commit 730862d
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ workflows:
- build_6
- build_8
filters:
branches:
only: master
tags:
only: /v[0-9]+(\.[0-9]+)*/
- deploy:
Expand Down
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
# transmit-update-loader

[![CircleCI](https://circleci.com/gh/occar421/transmit-update-loader/tree/master.svg?style=svg)](https://circleci.com/gh/occar421/transmit-update-loader/tree/master)
[![Build status](https://ci.appveyor.com/api/projects/status/slqhhh1kuiatmtaf/branch/master?svg=true)](https://ci.appveyor.com/project/occar421/transmit-update-loader/branch/master)

Message passing tool to transmit update to another file during webpack loader process.

# Use case

Assume these file structure while using CSS Modules.

```
+- src/
+- Button.tsx
+- Button.css
+- Button.css.d.ts
```

Here, also assume we use webpack Hot Module Replacement for dev server.
When 'Button.css' is updated, 'Button.css.d.ts' could be updated.
Although, 'Button.tsx' will not be notified that 'Button.css.d.ts' is updated.
If 'Button.css's selector has changed, 'Button.tsx' won't be decorated correctly.

Fortunately, it seems that webpack detects update with watching the same event when it is `touch`-ed.
This module helps that situation.

'Button.css' -(generate)-> 'Button.css.d.ts' -(watch)-(`touch`)-> 'Button.tsx' recompile.

# TODO

* Options
* Transform target name
* [TBD]
* CI / CD pipeline.
* Throttle
* [TBD]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "transmit-update-loader",
"version": "0.1.0",
"version": "0.1.1",
"description": "Message passing tool to transmit update to another file during webpack loader process.",
"main": "src/loader.js",
"repository": "https://github.com/occar421/transmit-update-loader",
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/txt.foo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TxtFoo
42 changes: 38 additions & 4 deletions test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import {

afterEach(removeGeneratedFiles);

it("should not affect file content", async () => {
const targetFileName = "./fixtures/foo.txt";
const status = await compiler(targetFileName, {
it("should not affect file content in webpack pipeline", async () => {
const sourceFileName = "./fixtures/foo.txt";
const sourceFileContent = await readFileAsync(sourceFileName);
const status = await compiler(sourceFileName, {
transmitRules: [{ test: /\/(.*$)/, targets: ["$1.null"] }]
});
const output = status.toJson().modules[0].source;
expect(output).toBe(await readFileAsync(targetFileName));
expect(output).toBe(sourceFileContent);
});

it("should not renew itself by default", async () => {
Expand Down Expand Up @@ -140,3 +141,36 @@ it("should create a new file if option is set", async () => {
});
expect(await existsAsync(targetFileName)).toBe(true);
});

it("should renew txt.foo from foo.txt with complex rule", async () => {
const sourceFileName = "./fixtures/foo.txt";
const targetFileName = "./fixtures/txt.foo";
const preStat = await fileStatAsync(targetFileName);
await compiler(sourceFileName, {
transmitRules: [{ test: /(\w+)\.(txt$)/, targets: ["$2.$1"] }]
});
const postStatFoo = await fileStatAsync(targetFileName);
expect(postStatFoo.ctime.getTime()).toBeGreaterThan(preStat.ctime.getTime());
});

it("should not affect source file content", async () => {
const sourceFileName = "./fixtures/foo.txt";
const preSourceFileContent = await readFileAsync(sourceFileName);
await compiler(sourceFileName, {
transmitRules: [{ test: /\/(.*$)/, targets: ["$1.null"] }],
noCreate: false
});
const postSourceFileContent = await readFileAsync(sourceFileName);
expect(postSourceFileContent).toBe(preSourceFileContent);
});

it("should not affect target file content", async () => {
const sourceFileName = "./fixtures/foo.txt";
const targetFileName = "./fixtures/foo.md";
const preTargetFileContent = await readFileAsync(targetFileName);
await compiler(sourceFileName, {
transmitRules: [{ test: /(\.txt$)/, targets: [".md"] }]
});
const postTargetFileContent = await readFileAsync(targetFileName);
expect(postTargetFileContent).toBe(preTargetFileContent);
});

0 comments on commit 730862d

Please sign in to comment.