Skip to content

Commit cb7049f

Browse files
authored
Merge pull request #1245 from pattern-lab/revert-1225-feature/yarn-workspaces
Revert "Better support for Yarn workspaces"
2 parents 8377d99 + 533b3f8 commit cb7049f

File tree

16 files changed

+177
-163
lines changed

16 files changed

+177
-163
lines changed

packages/cli/bin/install-edition.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ const {
1111
writeJsonAsync,
1212
getJSONKey,
1313
} = require('./utils');
14-
const {
15-
resolveFileInPackage,
16-
resolveDirInPackage,
17-
} = require('@pattern-lab/core/src/lib/resolver');
1814

1915
// https://github.com/TehShrike/deepmerge#overwrite-array
2016
const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray;
@@ -35,7 +31,7 @@ const installEdition = (edition, config, projectDir) => {
3531
const sourceDir = config.paths.source.root;
3632
yield checkAndInstallPackage(edition); // 1
3733
yield copyAsync(
38-
resolveDirInPackage(edition, 'source', '_meta'),
34+
path.resolve('./node_modules', edition, 'source', '_meta'),
3935
path.resolve(sourceDir, '_meta')
4036
); // 2
4137
pkg.dependencies = Object.assign(
@@ -49,15 +45,16 @@ const installEdition = (edition, config, projectDir) => {
4945
// 4.1
5046
case '@pattern-lab/edition-node-gulp': {
5147
yield copyAsync(
52-
resolveFileInPackage(edition, 'gulpfile.js'),
48+
path.resolve('./node_modules', edition, 'gulpfile.js'),
5349
path.resolve(sourceDir, '../', 'gulpfile.js')
5450
);
5551
break;
5652
}
5753
// 4.2
5854
case '@pattern-lab/edition-node': {
59-
const editionConfigPath = resolveFileInPackage(
60-
edition,
55+
const editionPath = path.resolve('./node_modules', edition);
56+
const editionConfigPath = path.resolve(
57+
editionPath,
6158
'patternlab-config.json'
6259
);
6360

@@ -70,7 +67,7 @@ const installEdition = (edition, config, projectDir) => {
7067
);
7168

7269
yield copyAsync(
73-
resolveFileInPackage(edition, 'helpers', 'test.js'),
70+
path.join(editionPath, path.sep, 'helpers', path.sep, 'test.js'),
7471
path.resolve(sourceDir, '../', 'helpers/test.js')
7572
);
7673

@@ -79,8 +76,9 @@ const installEdition = (edition, config, projectDir) => {
7976
}
8077
// 4.3
8178
case '@pattern-lab/edition-twig': {
82-
const editionConfigPath = resolveFileInPackage(
83-
edition,
79+
const editionPath = path.resolve('./node_modules', edition);
80+
const editionConfigPath = path.resolve(
81+
editionPath,
8482
'patternlab-config.json'
8583
);
8684
const editionConfig = require(editionConfigPath);
@@ -92,7 +90,7 @@ const installEdition = (edition, config, projectDir) => {
9290
);
9391

9492
yield copyAsync(
95-
resolveFileInPackage(edition, 'alter-twig.php'),
93+
path.resolve(editionPath, 'alter-twig.php'),
9694
path.resolve(sourceDir, '../', 'alter-twig.php')
9795
);
9896

packages/cli/bin/install-plugin.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
'use strict';
22

3+
const path = require('path');
4+
35
const _ = require('lodash');
46

5-
const { checkAndInstallPackage, wrapAsync } = require('./utils');
6-
const { resolveFileInPackage } = require('@pattern-lab/core/src/lib/resolver');
7+
const checkAndInstallPackage = require('./utils').checkAndInstallPackage;
8+
const wrapAsync = require('./utils').wrapAsync;
79

810
const installPlugin = (plugin, config) =>
911
wrapAsync(function*() {
@@ -14,7 +16,9 @@ const installPlugin = (plugin, config) =>
1416
_.set(config, `plugins[${name}]['initialized']`, false);
1517

1618
// Get the options from the plugin, if any
17-
const pluginPathConfig = resolveFileInPackage(name, 'config.json');
19+
const pluginPathConfig = path.resolve(
20+
path.join(process.cwd(), 'node_modules', name, 'config.json')
21+
);
1822
try {
1923
const pluginConfigJSON = require(pluginPathConfig);
2024
if (!_.has(config.plugins[name].options)) {

packages/cli/bin/install-starterkit.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@ const {
77
checkAndInstallPackage,
88
readJsonAsync,
99
} = require('./utils');
10-
const {
11-
resolveFileInPackage,
12-
resolveDirInPackage,
13-
} = require('@pattern-lab/core/src/lib/resolver');
1410

1511
const installStarterkit = (starterkit, config) =>
1612
wrapAsync(function*() {
1713
const sourceDir = config.paths.source.root;
1814
const name = starterkit.value || starterkit;
1915
yield checkAndInstallPackage(name);
20-
yield copyAsync(resolveDirInPackage(name, 'dist'), path.resolve(sourceDir));
16+
const kitPath = path.resolve('./node_modules', name);
17+
yield copyAsync(path.resolve(kitPath, 'dist'), path.resolve(sourceDir));
2118
let kitConfig;
22-
const kitConfigPath = resolveFileInPackage(name, 'patternlab-config.json');
19+
const kitConfigPath = path.resolve(kitPath, 'patternlab-config.json');
2320
if (fs.existsSync(kitConfigPath)) {
2421
kitConfig = yield readJsonAsync(kitConfigPath);
2522
}

packages/cli/bin/utils.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const path = require('path');
66
const chalk = require('chalk');
77
const EventEmitter = require('events').EventEmitter;
88
const hasYarn = require('has-yarn');
9-
const { resolveFileInPackage } = require('@pattern-lab/core/src/lib/resolver');
109

1110
/**
1211
* @name log
@@ -125,7 +124,7 @@ const copyWithPattern = (cwd, pattern, dest) =>
125124

126125
/**
127126
* @func fetchPackage
128-
* @desc Fetches packages from an npm package registry and adds a reference in the package.json under dependencies
127+
* @desc Fetches and saves packages from npm into node_modules and adds a reference in the package.json under dependencies
129128
* @param {string} packageName - The package name
130129
*/
131130
const fetchPackage = packageName =>
@@ -194,7 +193,7 @@ const getJSONKey = (packageName, key, fileName = 'package.json') =>
194193
wrapAsync(function*() {
195194
yield checkAndInstallPackage(packageName);
196195
const jsonData = yield fs.readJson(
197-
resolveFileInPackage(packageName, fileName)
196+
path.resolve('node_modules', packageName, fileName)
198197
);
199198
return jsonData[key];
200199
});

packages/core/patternlab-config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
"uikits": [
9292
{
9393
"name": "uikit-workshop",
94-
"package": "@pattern-lab/uikit-workshop",
9594
"outputDir": "",
9695
"enabled": true,
9796
"excludedPatternStates": [],

packages/core/src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ const patternlab_module = function(config) {
205205
},
206206

207207
/**
208-
* Installs plugin already available as a package dependency
208+
* Installs plugin already available via `node_modules/`
209209
*
210210
* @memberof patternlab
211211
* @name installplugin
@@ -214,6 +214,8 @@ const patternlab_module = function(config) {
214214
* @returns {void}
215215
*/
216216
installplugin: function(pluginName) {
217+
//get the config
218+
const configPath = path.resolve(process.cwd(), 'patternlab-config.json');
217219
const plugin_manager = new pm();
218220

219221
plugin_manager.install_plugin(pluginName);
@@ -232,7 +234,7 @@ const patternlab_module = function(config) {
232234
},
233235

234236
/**
235-
* Loads starterkit already available as a package dependency
237+
* Loads starterkit already available via `node_modules/`
236238
*
237239
* @memberof patternlab
238240
* @name loadstarterkit

packages/core/src/lib/loaduikits.js

Lines changed: 49 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,110 +5,91 @@ const _ = require('lodash');
55

66
const logger = require('./log');
77

8-
const { resolvePackageFolder } = require('./resolver');
9-
8+
let findModules = require('./findModules'); //eslint-disable-line prefer-const
109
let fs = require('fs-extra'); // eslint-disable-line
1110

12-
const readModuleFile = (uikitLocation, subPath) => {
11+
const uiKitMatcher = /^uikit-(.*)$/;
12+
const nodeModulesPath = path.join(process.cwd(), 'node_modules');
13+
14+
/**
15+
* Given a path: return the uikit name if the path points to a valid uikit
16+
* module directory, or false if it doesn't.
17+
* @param filePath
18+
* @returns UIKit name if exists or FALSE
19+
*/
20+
const isUIKitModule = filePath => {
21+
const baseName = path.basename(filePath);
22+
const engineMatch = baseName.match(uiKitMatcher);
23+
24+
if (engineMatch) {
25+
return engineMatch[1];
26+
}
27+
return false;
28+
};
29+
30+
const readModuleFile = (kit, subPath) => {
1331
return fs.readFileSync(
14-
path.resolve(path.join(uikitLocation, subPath)),
32+
path.resolve(path.join(kit.modulePath, subPath)),
1533
'utf8'
1634
);
1735
};
1836

1937
/**
2038
* Loads uikits, connecting configuration and installed modules
21-
* [1] Lists the enabled uikits from patternlab-config.json
22-
* [2] Try to resolve the location of the uikit in the package dependencies
23-
* [3] Warn when the uikit couldn't be loaded
39+
* [1] Looks in node_modules for uikits.
40+
* [2] Filter out our uikit-polyfills package.
41+
* [3] Only continue if uikit is enabled in patternlab-config.json
2442
* [4] Reads files from uikit that apply to every template
2543
* @param {object} patternlab
2644
*/
2745
module.exports = patternlab => {
2846
const paths = patternlab.config.paths;
2947

30-
const uikitConfigs = _.filter(patternlab.config.uikits, 'enabled'); // [1]
31-
uikitConfigs.forEach(uikitConfig => {
32-
let uikitLocation = null;
33-
if ('package' in uikitConfig) {
34-
try {
35-
uikitLocation = resolvePackageFolder(uikitConfig.package);
36-
} catch (ex) {
37-
logger.warning(
38-
`Could not find uikit with package name ${uikitConfig.package}. Did you add it to the 'dependencies' section in your 'package.json' file?`
39-
);
40-
return;
41-
}
42-
} else {
43-
// For backwards compatibility, name to package calculation is:
44-
// 1. name -> name
45-
// 2. name -> uikit-name
46-
// 3. name -> @pattern-lab/name
47-
// 4. name -> @pattern-lab/uikit-name
48-
for (const packageName of [
49-
uikitConfig.name,
50-
`uikit-${uikitConfig.name}`,
51-
`@pattern-lab/${uikitConfig.name}`,
52-
`@pattern-lab/uikit-${uikitConfig.name}`,
53-
]) {
54-
try {
55-
uikitLocation = resolvePackageFolder(packageName); // [2]
56-
} catch (ex) {
57-
// Ignore
58-
}
59-
if (uikitLocation != null) {
60-
uikitConfig.package = packageName;
61-
logger.info(`Found uikit package ${packageName}`);
62-
break;
63-
}
64-
}
65-
if (uikitLocation == null) {
66-
logger.warning(
67-
`Could not find uikit with package name ${uikitConfig.name}, uikit-${uikitConfig.name}, @pattern-lab/${uikitConfig.name} or @pattern-lab/uikit-${uikitConfig.name} defined within patternlab-config.json in the package dependencies.`
68-
);
69-
return;
70-
} else {
71-
logger.warning(
72-
`Please update the configuration of UIKit ${uikitConfig.name} with property 'package: ${uikitConfig.package}' in patternlab-config.json. Lookup by 'name' is deprecated and will be removed in the future.`
73-
);
74-
} // [3]
48+
const uikits = findModules(nodeModulesPath, isUIKitModule) // [1]
49+
.filter(kit => kit.name !== 'polyfills'); // [2]
50+
uikits.forEach(kit => {
51+
const configEntry = _.find(_.filter(patternlab.config.uikits, 'enabled'), {
52+
name: `uikit-${kit.name}`,
53+
}); // [3]
54+
55+
if (!configEntry) {
56+
logger.warning(
57+
`Could not find uikit with name uikit-${kit.name} defined within patternlab-config.json, or it is not enabled.`
58+
);
59+
return;
7560
}
7661

7762
try {
78-
patternlab.uikits[uikitConfig.name] = {
79-
name: uikitConfig.name,
80-
package: uikitConfig.package,
81-
modulePath: uikitLocation,
63+
patternlab.uikits[`uikit-${kit.name}`] = {
64+
name: `uikit-${kit.name}`,
65+
modulePath: kit.modulePath,
8266
enabled: true,
83-
outputDir: uikitConfig.outputDir,
84-
excludedPatternStates: uikitConfig.excludedPatternStates,
85-
excludedTags: uikitConfig.excludedTags,
67+
outputDir: configEntry.outputDir,
68+
excludedPatternStates: configEntry.excludedPatternStates,
69+
excludedTags: configEntry.excludedTags,
8670
header: readModuleFile(
87-
uikitLocation,
71+
kit,
8872
paths.source.patternlabFiles['general-header']
8973
),
9074
footer: readModuleFile(
91-
uikitLocation,
75+
kit,
9276
paths.source.patternlabFiles['general-footer']
9377
),
9478
patternSection: readModuleFile(
95-
uikitLocation,
79+
kit,
9680
paths.source.patternlabFiles.patternSection
9781
),
9882
patternSectionSubType: readModuleFile(
99-
uikitLocation,
83+
kit,
10084
paths.source.patternlabFiles.patternSectionSubtype
10185
),
102-
viewAll: readModuleFile(
103-
uikitLocation,
104-
paths.source.patternlabFiles.viewall
105-
),
86+
viewAll: readModuleFile(kit, paths.source.patternlabFiles.viewall),
10687
}; // [4]
10788
} catch (ex) {
10889
logger.error(ex);
10990
logger.error(
11091
'\nERROR: missing an essential file from ' +
111-
uikitLocation +
92+
kit.modulePath +
11293
paths.source.patternlabFiles +
11394
". Pattern Lab won't work without this file.\n"
11495
);

packages/core/src/lib/resolver.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

packages/core/src/lib/starterkit_manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const starterkit_manager = function(config) {
2929
kitDirStats = fs.statSync(kitPath);
3030
} catch (ex) {
3131
logger.warning(
32-
`${starterkitName} not found, use npm or another package manager to install it first.`
32+
`${starterkitName} not found, use npm to install it first.`
3333
);
3434
logger.warning(`${starterkitName} not loaded.`);
3535
return;

0 commit comments

Comments
 (0)