Skip to content

Commit

Permalink
Merge pull request #34 from piercefreeman/feature/package-esm-and-common
Browse files Browse the repository at this point in the history
Bundle CommonJS and ESM in one module. Also update the docs for the new module export format.

Alongside these packaging changes, increase unit test coverage and add additional tests for race conditions that appear in live concurrency settings.
  • Loading branch information
piercefreeman authored Oct 25, 2022
2 parents f165361 + fcd8f7a commit 28c3a15
Show file tree
Hide file tree
Showing 28 changed files with 871 additions and 159 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/groove.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,7 @@ jobs:
- name: Run test
run:
docker run ${{ env.IMAGE }}:groove-${{ github.sha }} test-go

- name: Run race condition tests
run:
docker run ${{ env.IMAGE }}:groove-${{ github.sha }} race-go
4 changes: 1 addition & 3 deletions groove/groove-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ npx @piercefreeman/groove install-ca
```

```javascript
import { Grove } from '@piercefreeman/groove'
import { TapeSession } from '@piercefreeman/groove/tape'
import { fetchWithProxy } from '@piercefreeman/groove/utilities'
import { Grove, TapeSession, fetchWithProxy } from '@piercefreeman/groove'

const main = async () => {
const proxy = new Groove(
Expand Down
51 changes: 51 additions & 0 deletions groove/groove-node/esbuild-hook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const Module = require("module");
const { transformSync } = require("esbuild");
const sourceMapSupport = require("source-map-support");

const cache = {};

function esbuildHook(code, filepath) {
const result = transformSync(code, {
target: "node16",
sourcemap: "both",
loader: "ts",
format: "cjs",
sourcefile: filepath,
});

cache[filepath] = {
url: filepath,
code: result.code,
map: result.map,
};

return result.code;
}

sourceMapSupport.install({
environment: "node",
retrieveFile(pathOrUrl) {
const file = cache[pathOrUrl];
if (file) {
return file.code;
} else {
return "";
}
},
});

const defaultLoader = Module._extensions[".js"];

Module._extensions[".ts"] = function (mod, filename) {
if (filename.includes("node_modules")) {
return defaultLoader(mod, filename);
}

const defaultCompile = mod._compile;
mod._compile = function (code) {
mod._compile = defaultCompile;
return mod._compile(esbuildHook(code, filename), filename);
};

defaultLoader(mod, filename);
};
2 changes: 1 addition & 1 deletion groove/groove-node/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
module.exports = {
transform: {'^.+\\.ts?$': 'ts-jest'},
testEnvironment: 'node',
testRegex: '/tests/.*\\.(test|spec)?\\.(ts|tsx)$',
testRegex: '/__tests__/.*\\.(test|spec)?\\.(ts|tsx)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node']
};
Loading

0 comments on commit 28c3a15

Please sign in to comment.