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

Feature/configurable symlink paths #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions types.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ 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);
const remoteCatalogRoot = (
process.platform == "win32"
) ?
Plugin.convertToOSPath( tropohouse.root )
: tropohouse.root;
var writer = new Writer(appPath, remoteCatalogRoot);

var catalog;
var setupFinished = false;
Expand All @@ -21,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');

Expand Down Expand Up @@ -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)) {
Expand Down
34 changes: 31 additions & 3 deletions writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ const fs = require('fs');
const path = require('path');
const log = require('./log.js');

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 {
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');

Expand Down Expand Up @@ -77,6 +84,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 ? symlinkOverrides.remoteCatalogRoot : symlinkOverrides.appPath;

return path.replace(pathToReplace, reaplacementPath);
}

writeToDisk() {
log('writing to disk');
for (const entry of this.packages.entries()) {
Expand All @@ -102,13 +125,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'
);
Expand Down