From 8418f04067b5549d9df6a9ca9eac65442e5cc6be Mon Sep 17 00:00:00 2001 From: varofon Date: Wed, 30 Oct 2024 15:13:43 +0200 Subject: [PATCH 1/3] log paths --- types.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/types.js b/types.js index adb1d44..263d5f9 100644 --- a/types.js +++ b/types.js @@ -6,6 +6,7 @@ const ProjectContext = require('./tools-imports.js').ProjectContext; const tropohouse = require('./tools-imports.js').tropohouse; const path = require('path'); const fs = require('fs'); +const log = require('./log.js'); var appPath = process.cwd(); var writer = new Writer(appPath); @@ -74,6 +75,11 @@ class Linter { setupFinished = true; } + log('paths',{ + appPath, + remoteCatalogRoot + }) + var packages = loadPackages(appPath, catalog, remoteCatalogRoot); for(var entry of Object.entries(packages)) { From e2113ed967c0ccf2cf68d32591169514ef2a49bf Mon Sep 17 00:00:00 2001 From: varofon Date: Wed, 30 Oct 2024 16:20:27 +0200 Subject: [PATCH 2/3] allow to override symlink target paths with env variables --- types.js | 12 ++++++------ writer.js | 30 +++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/types.js b/types.js index 263d5f9..c1a48c7 100644 --- a/types.js +++ b/types.js @@ -9,7 +9,12 @@ const fs = require('fs'); const log = require('./log.js'); var appPath = process.cwd(); -var writer = new Writer(appPath); +const remoteCatalogRoot = ( + process.platform == "win32" +) ? + Plugin.convertToOSPath( tropohouse.root ) +: tropohouse.root; +var writer = new Writer(appPath, remoteCatalogRoot); var catalog; var setupFinished = false; @@ -22,11 +27,6 @@ ProjectContext.prototype.getProjectLocalDirectory = function () { return oldGetProjectLocalDirectory.apply(this, arguments); }; -let remoteCatalogRoot = ( - process.platform == "win32" - ) ? - Plugin.convertToOSPath( tropohouse.root ) - : tropohouse.root; const isLinting = process.argv.includes('lint'); diff --git a/writer.js b/writer.js index 47e11da..242f366 100644 --- a/writer.js +++ b/writer.js @@ -4,10 +4,13 @@ const fs = require('fs'); const path = require('path'); const log = require('./log.js'); +const shouldOverrideSymlinkTarget = process.env.SYMLINK_REMOTE_CATALOG_ROOT && process.env.SYMLINK_APP_PATH; + // Manages the files and folders in .meteor/local/types module.exports = class Writer { - constructor(appPath) { + constructor(appPath, remoteCatalogRoot) { this.appPath = appPath; + this.remoteCatalogRoot = remoteCatalogRoot; this.typesPath = path.resolve(appPath, '.meteor/local/types'); this.npmPackagePath = path.resolve(this.typesPath, 'node_modules/package-types'); @@ -77,6 +80,22 @@ module.exports = class Writer { return name.replace(':', '_'); } + getSymlinkTarget(path) { + // if there are no variable to override symlink target path + // then return it as is + if (!shouldOverrideSymlinkTarget) return path; + + // if zodern:types is running in a different enviornment from the + // development environment, then symlinks won't work properly + // we can use the following environment variables to override the + // symlink target path + const isRemote = path.includes(this.remoteCatalogRoot); + const pathToReplace = isRemote ? this.remoteCatalogRoot : this.appPath; + const reaplacementPath = isRemote ? process.env.SYMLINK_REMOTE_CATALOG_ROOT : process.env.SYMLINK_APP_PATH; + + return path.replace(pathToReplace, reaplacementPath); + } + writeToDisk() { log('writing to disk'); for (const entry of this.packages.entries()) { @@ -102,13 +121,18 @@ module.exports = class Writer { log('writing', name); let packageTypesPath = path.resolve(this.npmPackagePath, name); this.mkdirIfMIssing(packageTypesPath); + + // generate symlinks + const symlinkNodeModulesTarget = this.getSymlinkTarget(nodeModulesPath); fs.symlinkSync( - nodeModulesPath, + symlinkNodeModulesTarget, path.resolve(packageTypesPath, 'node_modules'), 'junction' ); + + const symlinkPackageTarget = this.getSymlinkTarget(packagePath); fs.symlinkSync( - packagePath, + symlinkPackageTarget, path.resolve(packageTypesPath, 'package'), 'junction' ); From 3891681f7414008dbc01fb3c52f65e8d126aa526 Mon Sep 17 00:00:00 2001 From: varofon Date: Wed, 30 Oct 2024 16:25:30 +0200 Subject: [PATCH 3/3] prefix env var name --- writer.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/writer.js b/writer.js index 242f366..d61774b 100644 --- a/writer.js +++ b/writer.js @@ -4,7 +4,11 @@ const fs = require('fs'); const path = require('path'); const log = require('./log.js'); -const shouldOverrideSymlinkTarget = process.env.SYMLINK_REMOTE_CATALOG_ROOT && process.env.SYMLINK_APP_PATH; +const shouldOverrideSymlinkTarget = process.env.ZODERN_TYPES_SYMLINK_REMOTE_CATALOG_ROOT && process.env.ZODERN_TYPES_SYMLINK_APP_PATH; +const symlinkOverrides = { + remoteCatalogRoot: process.env.ZODERN_TYPES_SYMLINK_REMOTE_CATALOG_ROOT, + appPath: process.env.ZODERN_TYPES_SYMLINK_APP_PATH +} // Manages the files and folders in .meteor/local/types module.exports = class Writer { @@ -91,7 +95,7 @@ module.exports = class Writer { // symlink target path const isRemote = path.includes(this.remoteCatalogRoot); const pathToReplace = isRemote ? this.remoteCatalogRoot : this.appPath; - const reaplacementPath = isRemote ? process.env.SYMLINK_REMOTE_CATALOG_ROOT : process.env.SYMLINK_APP_PATH; + const reaplacementPath = isRemote ? symlinkOverrides.remoteCatalogRoot : symlinkOverrides.appPath; return path.replace(pathToReplace, reaplacementPath); }