fyn 1.1.36 → 1.1.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/fyn.js +160 -24
  2. package/package.json +1 -1
package/dist/fyn.js CHANGED
@@ -2293,6 +2293,7 @@ class DepItem {
2293
2293
 
2294
2294
  this.promoted = undefined;
2295
2295
  this.depth = parent && parent.depth + 1 || options.depth || 0;
2296
+ this.nameDepPath = this.depth > 1 ? parent.nameDepPath + "/" + this.name : this.name;
2296
2297
  this.priority = options.priority;
2297
2298
  }
2298
2299
 
@@ -3097,6 +3098,8 @@ const {
3097
3098
  const {
3098
3099
  parseYarnLock
3099
3100
  } = __webpack_require__("./yarn/index.js");
3101
+
3102
+ const mm = __webpack_require__("./node_modules/.f/_/minimatch/3.0.4/minimatch/minimatch.js");
3100
3103
  /* eslint-disable no-magic-numbers, max-statements, no-empty, complexity, no-eval */
3101
3104
 
3102
3105
 
@@ -3118,9 +3121,8 @@ class Fyn {
3118
3121
  _cliSource = {},
3119
3122
  _fynpo = true
3120
3123
  }) {
3121
- this._cliSource = _cliSource;
3124
+ this._cliSource = _objectSpread({}, _cliSource);
3122
3125
  const options = this._options = fynConfig(opts);
3123
- this._layout = options.layout;
3124
3126
  this._cwd = options.cwd || process.cwd();
3125
3127
  logger.debug(`fyn options`, JSON.stringify(fynTil.removeAuthInfo(options)));
3126
3128
  this.localPkgWithNestedDep = [];
@@ -3142,11 +3144,49 @@ class Fyn {
3142
3144
  }
3143
3145
  }
3144
3146
 
3147
+ checkLayoutOption() {
3148
+ const {
3149
+ _options,
3150
+ _cliSource
3151
+ } = this;
3152
+
3153
+ if (_options.flattenTop === false && _cliSource.flattenTop !== "default") {
3154
+ //
3155
+ if (_options.layout !== "detail") {
3156
+ if (_cliSource.layout === "default") {
3157
+ logger.info(`flatten-top option turned off by ${_cliSource.flattenTop}, so switching node_modules layout to detail`);
3158
+ _options.layout = "detail";
3159
+ _cliSource.layout = _cliSource.flattenTop;
3160
+ } else {
3161
+ logger.warn(`you try to turn off flatten-top but set node_modules layout to ${_options.layout} and they are not compatible`);
3162
+ }
3163
+ }
3164
+ }
3165
+ }
3166
+
3145
3167
  checkFynLockExist() {
3146
3168
  const fname = Path.join(this._cwd, FYN_LOCK_FILE);
3147
3169
  return Fs.existsSync(fname);
3148
3170
  }
3149
3171
 
3172
+ updateConfigInLockfile(name, newValue) {
3173
+ const valueInLock = this._depLocker.getConfig(name);
3174
+
3175
+ if (valueInLock !== undefined && valueInLock !== newValue) {
3176
+ if (this._cliSource[name] === "cli") {
3177
+ logger.info(`You are changing ${name} in your lockfile from ${valueInLock} to ${newValue}`);
3178
+
3179
+ this._depLocker.setConfig(name, newValue);
3180
+ } else {
3181
+ logger.info(`Setting ${name} to ${valueInLock} from your lockfile`);
3182
+ this._options[name] = valueInLock;
3183
+ this._cliSource[name] = "lock";
3184
+ }
3185
+ } else {
3186
+ this._depLocker.setConfig(name, newValue);
3187
+ }
3188
+ }
3189
+
3150
3190
  async readLockFiles() {
3151
3191
  if (this._depLocker) {
3152
3192
  return null;
@@ -3155,20 +3195,9 @@ class Fyn {
3155
3195
  this._npmLockData = null;
3156
3196
  this._depLocker = new PkgDepLocker(this.lockOnly, this._options.lockfile);
3157
3197
  const foundLock = await this._depLocker.read(Path.join(this._cwd, FYN_LOCK_FILE));
3158
-
3159
- const layout = this._depLocker.getConfig("layout");
3160
-
3161
- if (layout && layout !== this._layout) {
3162
- if (this._cliSource.layout === "cli") {
3163
- logger.info(`You are changing layout in your lockfile from ${layout} to ${this._layout}`);
3164
-
3165
- this._depLocker.setConfig("layout", this._layout);
3166
- } else {
3167
- logger.info(`Setting layout to ${layout} from your lockfile`);
3168
- }
3169
- } else {
3170
- this._depLocker.setConfig("layout", this._layout);
3171
- }
3198
+ this.updateConfigInLockfile("layout", this._options.layout);
3199
+ this.updateConfigInLockfile("flattenTop", this._options.flattenTop);
3200
+ this.checkLayoutOption();
3172
3201
 
3173
3202
  if (this._options.npmLock === true) {// force load npm lock data
3174
3203
  } else if (foundLock || this._options.npmLock === false) {
@@ -3203,7 +3232,7 @@ class Fyn {
3203
3232
  }
3204
3233
 
3205
3234
  get isNormalLayout() {
3206
- return this._layout === "normal";
3235
+ return this._options.layout === "normal";
3207
3236
  }
3208
3237
 
3209
3238
  async _initCentralStore() {
@@ -3297,10 +3326,10 @@ class Fyn {
3297
3326
  this._fynpo = await fynTil.loadFynpo(this._cwd); // TODO: options from CLI should not be override by fynpo config options
3298
3327
 
3299
3328
  _.merge(this._options, _.get(this, "_fynpo.fyn.options"));
3300
-
3301
- this._layout = this._options.layout;
3302
3329
  }
3303
3330
 
3331
+ this.checkLayoutOption();
3332
+
3304
3333
  if (!this._pkg) {
3305
3334
  const options = this._options;
3306
3335
  await this.loadPkg(options);
@@ -3358,6 +3387,23 @@ class Fyn {
3358
3387
  }
3359
3388
 
3360
3389
  this._runNpm = _.uniq([].concat(this._options.runNpm, fynpoNpmRun).filter(x => x));
3390
+
3391
+ const resData = _objectSpread(_objectSpread({}, this._pkg.resolutions), _.get(this._fynpo, ["config", "resolutions"]));
3392
+
3393
+ if (!_.isEmpty(resData)) {
3394
+ this._resolutions = resData;
3395
+ this._resolutionsMatchers = Object.keys(resData).map(depPath => {
3396
+ const unslashedPath = fynTil.unSlashNpmScope(depPath);
3397
+ const pts = unslashedPath.split("/"); // spec can only contain ** between slashes
3398
+
3399
+ assert(!pts.find(x => !(!x.includes("*") || x === "**")), `resolution path '${depPath}' can only contain '**' for wildcard matching`);
3400
+ const finalPath = pts.length === 1 ? `**/${unslashedPath}` : unslashedPath;
3401
+ return {
3402
+ mm: new mm.Minimatch(finalPath),
3403
+ res: resData[depPath]
3404
+ };
3405
+ });
3406
+ }
3361
3407
  }
3362
3408
  }
3363
3409
 
@@ -5868,7 +5914,8 @@ const {
5868
5914
 
5869
5915
  const {
5870
5916
  checkPkgOsCpu,
5871
- relativePath
5917
+ relativePath,
5918
+ unSlashNpmScope
5872
5919
  } = __webpack_require__("./lib/util/fyntil.js");
5873
5920
 
5874
5921
  const {
@@ -5896,6 +5943,8 @@ const {
5896
5943
  PACKAGE_RAW_INFO,
5897
5944
  DEP_ITEM
5898
5945
  } = __webpack_require__("./lib/symbols.js");
5946
+
5947
+ const failMetaMsg = name => `Unable to retrieve meta for package ${name} - If you've updated its version recently, try to run fyn with '--refresh-meta' again`;
5899
5948
  /*
5900
5949
  * Package dependencies resolver
5901
5950
  *
@@ -6948,6 +6997,69 @@ ${item.depPath.join(" > ")}`);
6948
6997
  resolved
6949
6998
  };
6950
6999
  }
7000
+ /**
7001
+ * Match a nested dep to user's resolutions data, or nested and direct dep for packages
7002
+ * inside a fynpo monorepo.
7003
+ *
7004
+ * spec: https://github.com/yarnpkg/rfcs/blob/master/implemented/0000-selective-versions-resolutions.md
7005
+ *
7006
+ * @param {*} item
7007
+ * @returns
7008
+ */
7009
+
7010
+
7011
+ _replaceWithResolutionsData(item) {
7012
+ if (!this._fyn._resolutions || item._semver.$$) {
7013
+ return undefined;
7014
+ } //
7015
+ // this item represent a direct dependency
7016
+ //
7017
+
7018
+
7019
+ if (item.depth < 2) {
7020
+ //
7021
+ // if we have a package within a fynpo monorepo, then we replace its direct
7022
+ // dependencies with resolutions data, vs only its nested dependencies
7023
+ // according to yarn's resolutions spec, because if local package A pull in
7024
+ // another local package B, then B's dependencies would end up being
7025
+ // subjected to resolutions data, so for consistency, we check resolutions
7026
+ // for all fynpo's local packages' direct dependencies.
7027
+ //
7028
+ if (!this._fyn.isFynpo) {
7029
+ // not a fynpo, avoid checking resolutions for direct dependencies
7030
+ return undefined;
7031
+ }
7032
+ }
7033
+
7034
+ let nameDepPath;
7035
+
7036
+ if (this._fyn.isFynpo) {
7037
+ nameDepPath = `${this._fyn._pkg.name}/${item.nameDepPath}`;
7038
+ } else {
7039
+ nameDepPath = item.nameDepPath;
7040
+ }
7041
+
7042
+ const unslashed = unSlashNpmScope(nameDepPath);
7043
+
7044
+ const found = this._fyn._resolutionsMatchers.find(r => r.mm.match(unslashed));
7045
+
7046
+ if (found && found.res && found.res !== "--no-change" && found.res !== item.semver) {
7047
+ const {
7048
+ res
7049
+ } = found;
7050
+ const msg = `${nameDepPath} changed to ${res} from ${item.semver} by resolutions data`;
7051
+
7052
+ if (item.depth < 2) {
7053
+ logger.info(`fynpo: ${msg}`);
7054
+ } else {
7055
+ logger.debug(msg);
7056
+ }
7057
+
7058
+ semverUtil.replace(item._semver, res);
7059
+ }
7060
+
7061
+ return undefined;
7062
+ }
6951
7063
 
6952
7064
  _resolveWithLockData(item) {
6953
7065
  //
@@ -7062,19 +7174,21 @@ ${item.depPath.join(" > ")}`);
7062
7174
  });
7063
7175
  };
7064
7176
 
7065
- const promise = !item.semverPath || this._fyn.preferLock ? tryLock().then(r => r || item.semverPath && tryLocal()) : tryLocal().then(r => r || tryLock());
7066
-
7067
- const failMetaMsg = name => `Unable to retrieve meta for package ${name} - If you've updated its version recently, try to run fyn with '--refresh-meta' again`;
7177
+ this._replaceWithResolutionsData(item);
7068
7178
 
7179
+ const promise = !item.semverPath || this._fyn.preferLock ? tryLock().then(r => r || item.semverPath && tryLocal()) : tryLocal().then(r => r || tryLock());
7069
7180
  return promise.then(r => {
7070
7181
  if (r && !_.get(r, ["meta", "versions", r.resolved, "_missingJson"])) {
7071
7182
  return r;
7072
7183
  }
7073
7184
 
7074
- if (this._lockOnly || item.localType) return undefined; // neither local nor lock was able to resolve for item
7185
+ if (this._lockOnly || item.localType) {
7186
+ return undefined;
7187
+ } // neither local nor lock was able to resolve for item
7075
7188
  // so try to fetch from registry for real meta to resolve
7076
7189
  // always fetch the item and let pkg src manager deal with caching
7077
7190
 
7191
+
7078
7192
  return this._pkgSrcMgr.fetchMeta(item).then(meta => {
7079
7193
  if (!meta) {
7080
7194
  throw new Error(failMetaMsg(item.name));
@@ -7116,6 +7230,11 @@ ${item.depPath.join(" > ")}`);
7116
7230
  meta,
7117
7231
  resolved
7118
7232
  } = r;
7233
+
7234
+ if (item._semver.$$ && !Semver.satisfies(resolved, item._semver.$$)) {
7235
+ logger.warn(`${item.nameDepPath}@${resolved} resolved by resolutions data doesn't satisfy original semver ${item._semver.$$}`);
7236
+ }
7237
+
7119
7238
  await this.addPackageResolution(item, meta, resolved);
7120
7239
  }).then(() => {
7121
7240
  const depthData = this._depthResolving[item.depth];
@@ -10183,6 +10302,17 @@ const fyntil = {
10183
10302
  },
10184
10303
  posixify,
10185
10304
 
10305
+ /**
10306
+ * Take a npm dependency path separated by / and replace the / that's meant for a npm scope with '+'
10307
+ *
10308
+ * @param {*} npmDepPath
10309
+ * @param {string} replacer string to replace the slash with
10310
+ * @returns dep path where npm scope's / replaced with '+'
10311
+ */
10312
+ unSlashNpmScope(npmDepPath, replacer = "+") {
10313
+ return npmDepPath.replace(/(\@[^\/]+)\//g, (_a, b) => `${b}${replacer}`);
10314
+ },
10315
+
10186
10316
  getGlobalNodeModules() {
10187
10317
  const nodeDir = Path.dirname(process.execPath);
10188
10318
 
@@ -11114,6 +11244,11 @@ function analyze(semver) {
11114
11244
 
11115
11245
  return sv;
11116
11246
  }
11247
+
11248
+ function replace(sv, replaced) {
11249
+ sv.$$ = sv.$;
11250
+ sv.$ = replaced;
11251
+ }
11117
11252
  /**
11118
11253
  * semver utilities lib
11119
11254
  */
@@ -11125,6 +11260,7 @@ const semverLib = {
11125
11260
  },
11126
11261
  split,
11127
11262
  analyze,
11263
+ replace,
11128
11264
  localify,
11129
11265
  localifyHard,
11130
11266
  unlocalify,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fyn",
3
- "version": "1.1.36",
3
+ "version": "1.1.39",
4
4
  "description": "The package manager for fynpo, a zero setup monorepo manager",
5
5
  "main": "./bin/fyn.js",
6
6
  "homepage": "https://jchip.github.io/fynpo/",