Skip to content

Commit

Permalink
fix(collectCalls): write CallExpressions to the cache dir
Browse files Browse the repository at this point in the history
Makes collectCalls work in PnP environments by not modifying ourselves
  • Loading branch information
merceyz committed Feb 22, 2020
1 parent d3cc1d0 commit 17405f5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@types/babel__core": "^7.1.5",
"@types/babel__generator": "^7.6.1",
"@types/babel__template": "^7.0.2",
"@types/find-cache-dir": "^2.0.0",
"@types/lodash": "^4.14.149",
"@types/node": "^12.12.17",
"@types/object-hash": "^1.3.0",
Expand All @@ -56,6 +57,7 @@
"@babel/generator": "^7.6.2",
"@babel/template": "^7.6.0",
"@babel/types": "^7.6.1",
"find-cache-dir": "^3.2.0",
"lodash": "^4.17.15",
"object-hash": "^2.0.3"
},
Expand Down
10 changes: 8 additions & 2 deletions src/visitors/collectCalls.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import generate from '@babel/generator';
import findCacheDir from 'find-cache-dir';
import fs from 'fs';
import path from 'path';
import { VisitorFunction } from '../types';
Expand All @@ -12,12 +13,17 @@ export const collectCalls: VisitorFunction = ({ expression, options, filename })
}

if (stream === null) {
const cacheDir = findCacheDir({ name: 'optimize-clsx', create: true });
if (!cacheDir) {
throw new Error('Unable to locate cache directory');
}

const filePath = path.join(
__dirname,
cacheDir,
`log-${new Date(Date.now()).toISOString().replace(/:/g, '.')}.js`,
);
stream = fs.createWriteStream(filePath, { flags: 'w' });
console.log('Writing calls to ' + filePath);
console.log('Writing CallExpressions to ' + filePath);
}

let locationStr = '';
Expand Down
38 changes: 37 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,13 @@ __metadata:
languageName: node
linkType: hard

"@types/find-cache-dir@npm:^2.0.0":
version: 2.0.0
resolution: "@types/find-cache-dir@npm:2.0.0"
checksum: 2/41b57ddeabf1e6b35d176ef583aea6b41447f4f096fb8f57bd9b20ac9a9f7569893ef34ab3f101c068e9b65c6dfca1e273f11aa82e68e7741354afa3e317856e
languageName: node
linkType: hard

"@types/istanbul-lib-coverage@npm:*, @types/istanbul-lib-coverage@npm:^2.0.0":
version: 2.0.1
resolution: "@types/istanbul-lib-coverage@npm:2.0.1"
Expand Down Expand Up @@ -1931,6 +1938,7 @@ __metadata:
"@types/babel__core": ^7.1.5
"@types/babel__generator": ^7.6.1
"@types/babel__template": ^7.0.2
"@types/find-cache-dir": ^2.0.0
"@types/lodash": ^4.14.149
"@types/node": ^12.12.17
"@types/object-hash": ^1.3.0
Expand All @@ -1939,6 +1947,7 @@ __metadata:
benchmark: ^2.1.4
classnames: ^2.2.6
clsx: ^1.0.4
find-cache-dir: ^3.2.0
husky: ^4.2.3
jest: ^24.9.0
lodash: ^4.17.15
Expand Down Expand Up @@ -2349,6 +2358,13 @@ __metadata:
languageName: node
linkType: hard

"commondir@npm:^1.0.1":
version: 1.0.1
resolution: "commondir@npm:1.0.1"
checksum: 2/98f18ad14f0ea38e0866db365bc8496f2a74250cf47ec96b94913e1b0574c99b4ff837a9f05dbc68d82505fd06b52dfba4f6bbe6fbda43094296cfaf33b475a0
languageName: node
linkType: hard

"compare-func@npm:^1.3.1":
version: 1.3.2
resolution: "compare-func@npm:1.3.2"
Expand Down Expand Up @@ -3248,6 +3264,17 @@ __metadata:
languageName: node
linkType: hard

"find-cache-dir@npm:^3.2.0":
version: 3.2.0
resolution: "find-cache-dir@npm:3.2.0"
dependencies:
commondir: ^1.0.1
make-dir: ^3.0.0
pkg-dir: ^4.1.0
checksum: 2/8c45c3b15db71d54027ef8ab3f96ba52e1238cb8bc5125b2da1ed69e71e931448818278523324855316bed23ec61810e8cbf48e54b2d6209a649ec57268dde9d
languageName: node
linkType: hard

"find-up@npm:4.1.0, find-up@npm:^4.0.0, find-up@npm:^4.1.0":
version: 4.1.0
resolution: "find-up@npm:4.1.0"
Expand Down Expand Up @@ -4951,6 +4978,15 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"make-dir@npm:^3.0.0":
version: 3.0.2
resolution: "make-dir@npm:3.0.2"
dependencies:
semver: ^6.0.0
checksum: 2/ed464f083653c71e9045781d302942cfabcb6e7282aa3410857d7556b3d78ad5e50a75598111c2eab9531d3ec8c5ec3fe11275b5a6c83748f6a48025a0b40518
languageName: node
linkType: hard

"make-error@npm:1.x":
version: 1.3.5
resolution: "make-error@npm:1.3.5"
Expand Down Expand Up @@ -5879,7 +5915,7 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"pkg-dir@npm:^4.2.0":
"pkg-dir@npm:^4.1.0, pkg-dir@npm:^4.2.0":
version: 4.2.0
resolution: "pkg-dir@npm:4.2.0"
dependencies:
Expand Down

0 comments on commit 17405f5

Please sign in to comment.