Skip to content

Commit

Permalink
added fix for typescript asset invalidation (#2485)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullahtariq1171 authored and devongovett committed Jan 16, 2019
1 parent a4eb94e commit d7dc51f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
9 changes: 2 additions & 7 deletions packages/core/parcel-bundler/src/assets/JSAsset.js
Expand Up @@ -16,6 +16,7 @@ const hoist = require('../scope-hoisting/hoist');
const path = require('path');
const fs = require('@parcel/fs');
const logger = require('@parcel/logger');
const isAccessedVarChanged = require('../utils/isAccessedVarChanged');

const IMPORT_RE = /\b(?:import\b|export\b|require\s*\()/;
const ENV_RE = /\b(?:process\.env)\b/;
Expand All @@ -40,13 +41,7 @@ class JSAsset extends Asset {
}

shouldInvalidate(cacheData) {
for (let key in cacheData.env) {
if (cacheData.env[key] !== process.env[key]) {
return true;
}
}

return false;
return isAccessedVarChanged(cacheData);
}

mightHaveDependencies() {
Expand Down
6 changes: 6 additions & 0 deletions packages/core/parcel-bundler/src/assets/TypeScriptAsset.js
@@ -1,10 +1,16 @@
const Asset = require('../Asset');
const localRequire = require('../utils/localRequire');
const isAccessedVarChanged = require('../utils/isAccessedVarChanged');

class TypeScriptAsset extends Asset {
constructor(name, options) {
super(name, options);
this.type = 'js';
this.cacheData.env = {};
}

shouldInvalidate(cacheData) {
return isAccessedVarChanged(cacheData);
}

async generate() {
Expand Down
14 changes: 14 additions & 0 deletions packages/core/parcel-bundler/src/utils/isAccessedVarChanged.js
@@ -0,0 +1,14 @@
/*
Checks if any of the used variable from process.env is changed
*/
function isAccessedVarChanged(cacheData) {
for (let key in cacheData.env) {
if (cacheData.env[key] !== process.env[key]) {
return true;
}
}

return false;
}

module.exports = isAccessedVarChanged;

0 comments on commit d7dc51f

Please sign in to comment.