Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added fix for typescript asset invalidation #2485

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;