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

fix(project): build issues on windows #4823

Merged
merged 21 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b1036ee
fix(bundler): inline command path resolution in windows
mecolela Dec 6, 2019
e662283
fix(elements): build tasks path resolution in windows
mecolela Dec 6, 2019
10aacc6
fix(icon-build-helpers): react & vanilla builders path resolution in …
mecolela Dec 6, 2019
2035955
fix(icons-vue): path resolution in windows & improve logging
mecolela Dec 6, 2019
ada870b
Merge branch 'master' into windows-support
sichangi Dec 6, 2019
9bf826a
fix(bundler): inconsistent sass module finder & code styling issues
mecolela Dec 7, 2019
f93cc97
Merge remote-tracking branch 'origin/windows-support' into windows-su…
mecolela Dec 7, 2019
20e0ae2
Merge branch 'master' into windows-support
sichangi Dec 7, 2019
6d381f3
Merge remote-tracking branch 'origin/windows-support' into windows-su…
mecolela Dec 7, 2019
f082ab5
chore: use native path separator
mecolela Dec 7, 2019
0bb8688
Merge branch 'master' into windows-support
sichangi Dec 18, 2019
2fcb247
Merge branch 'master' into windows-support
sichangi Jan 5, 2020
bcaad8e
Merge branch 'master' into windows-support
joshblack Jan 6, 2020
031a7cf
fix: moduleName prefixing logic
mecolela Jan 6, 2020
acd6ab5
Merge branch 'master' into windows-support
sichangi Jan 6, 2020
d5433b8
Merge branch 'master' into windows-support
sichangi Jan 7, 2020
74a897d
chore: improve root directory check logic
mecolela Jan 8, 2020
ee0a613
Merge remote-tracking branch 'origin/windows-support' into windows-su…
mecolela Jan 8, 2020
59cf50c
Merge branch 'master' into windows-support
sichangi Jan 9, 2020
e029841
Merge branch 'master' into windows-support
joshblack Jan 10, 2020
f8c5c99
Merge branch 'master' into windows-support
joshblack Jan 10, 2020
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
30 changes: 19 additions & 11 deletions packages/bundler/src/commands/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const fs = require('fs-extra');
const klaw = require('klaw-sync');
const os = require('os');
const path = require('path');
const isWin = process.platform === 'win32';
const replace = require('replace-in-file');
const { reporter } = require('@carbon/cli-reporter');

const tmpDir = os.tmpdir();

Expand All @@ -24,12 +26,14 @@ async function inline(options, info) {

await Promise.all([fs.remove(inlineFolder), fs.remove(vendorFolder)]);

reporter.info('Inlining sass dependencies');
await inlineSassDependencies(
packageJsonPath,
sourceFolder,
vendorFolder,
cwd
);
reporter.success('Done');
}

async function inlineSassDependencies(
Expand All @@ -50,8 +54,9 @@ async function inlineSassDependencies(
];
const inlinedDependencies = (await Promise.all(
allPossibleDependencies.map(async dependency => {
const [packageFolder, scssFolder] = await findSassModule(dependency, cwd);
if (packageFolder) {
const modules = await findSassModule(dependency, cwd);
if (modules) {
const [scssFolder] = modules;
const dependencyOutputFolder = path.join(vendorFolder, dependency);

await fs.copy(scssFolder, dependencyOutputFolder);
Expand Down Expand Up @@ -84,11 +89,7 @@ async function inlineSassDependencies(
return false;
}

if (path.basename(src) === 'index.scss') {
return false;
}

return true;
return path.basename(src) !== 'index.scss';
},
});
await fs.copy(tmpFolder, inlineFolder);
Expand All @@ -113,7 +114,9 @@ async function inlineSassDependencies(
files: file.path,
from: REPLACE_REGEX,
to(_, match) {
return `@import '${relativeImportPath}/${match}`;
return `@import '${
sichangi marked this conversation as resolved.
Show resolved Hide resolved
isWin ? relativeImportPath.replace('\\', '/') : relativeImportPath
}/${match}`;
},
});
})
Expand All @@ -123,20 +126,25 @@ async function inlineSassDependencies(
function findSassModule(packageName, cwd) {
let currentDirectory = cwd;

while (currentDirectory !== '/') {
const isNotRoot = () =>
isWin
? !/^[a-zA-Z]:(\/\/|\\)$/.test(currentDirectory)
: currentDirectory !== '/';

while (isNotRoot()) {
sichangi marked this conversation as resolved.
Show resolved Hide resolved
const nodeModulesFolder = path.join(currentDirectory, 'node_modules');
const packageFolder = path.join(nodeModulesFolder, packageName);
const scssFolder = path.join(packageFolder, 'scss');
const packageJsonPath = path.join(packageFolder, 'package.json');

if (fs.existsSync(scssFolder)) {
return [packageFolder, scssFolder, packageJsonPath];
return [scssFolder, packageFolder, packageJsonPath];
}

currentDirectory = path.dirname(currentDirectory);
}

return [false];
return false;
}

module.exports = inline;
2 changes: 1 addition & 1 deletion packages/elements/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function build() {
const paths = klaw(BUNDLE_DIR, {
nodir: true,
filter(item) {
const paths = item.path.split('/');
const paths = item.path.split(path.sep);
const filename = paths[paths.length - 1];
const folder = paths[paths.length - 3];

Expand Down
9 changes: 7 additions & 2 deletions packages/icon-build-helpers/src/builders/react/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'use strict';

const { camel } = require('change-case');
const { reporter } = require('@carbon/cli-reporter');
const fs = require('fs-extra');
const path = require('path');
const { rollup } = require('rollup');
Expand Down Expand Up @@ -71,6 +72,7 @@ ${modules.map(({ source }) => `export ${source}`).join('\n')}
export { Icon };
`;

reporter.info('Building components');
const bundle = await rollup({
input: '__entrypoint__.js',
external,
Expand Down Expand Up @@ -106,6 +108,7 @@ export { Icon };
})
);

reporter.info('Creating aliases');
// Create aliases for `@carbon/icons-react/es/<icon-name>/<size>`
await Promise.all(
meta.map(async icon => {
Expand All @@ -114,7 +117,7 @@ export { Icon };
// The length of this is determined by the number of directories from
// our `outputOptions` minus 1 for the bundle type (`es` for example)
// and minus 1 for the filename as it does not count as a directory jump
length: outputOptions.file.split('/').length - 2,
length: outputOptions.file.split(path.sep).length - 2,
})
.fill('..')
.join('/');
Expand All @@ -141,7 +144,7 @@ export default ${moduleName};
// Drop the first part of `outputOptions.file` as it contains the `es/`
// directory
const commonjsFilepath = outputOptions.file
.split('/')
.split(path.sep)
.slice(1)
.join('/');
const { source: component } = createIconComponent(moduleName, descriptor);
Expand All @@ -165,6 +168,7 @@ export default ${moduleName};`;
};
}, {});

reporter.info('Bundling Javascript modules');
// Using the mapping of file path to file source, we can specify our input to
// rollup by formatting the filepath so that rollup outputs the file to the
// correct place. The location is going to match the key that we use in the
Expand Down Expand Up @@ -200,6 +204,7 @@ export default ${moduleName};`;
],
});

reporter.info('Writing to destination');
await commonjsBundles.write({
dir: 'lib',
format: 'cjs',
Expand Down
5 changes: 4 additions & 1 deletion packages/icon-build-helpers/src/builders/vanilla/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,16 @@ async function builder(source, { cwd } = {}) {
function getModuleName(name, size, prefixParts, descriptor) {
const width = parseInt(descriptor.attrs.width, 10);
const height = parseInt(descriptor.attrs.height, 10);
const prefix = prefixParts
let prefix = prefixParts
.filter(size => isNaN(size))
.map(pascal)
.join('');
const isGlyph = width < 16 || height < 16;

if (prefix !== '') {
if (prefix.match(/^\d/)) {
prefix = '_' + prefix;
}
if (!size) {
if (isGlyph) {
return prefix + pascal(name) + 'Glyph';
Expand Down
21 changes: 16 additions & 5 deletions packages/icons-vue/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
'use strict';

const meta = require('@carbon/icons/build-info.json');
const { reporter } = require('@carbon/cli-reporter');
const { rollup } = require('rollup');
const babel = require('rollup-plugin-babel');
const virtual = require('./plugins/virtual');
const { createIconComponent } = require('./createIconComponent');
const isWin = process.platform === 'win32';

const BUNDLE_FORMATS = [
{
Expand Down Expand Up @@ -46,11 +48,14 @@ const babelConfig = {
* building icon components built on top of the `<Icon>` primitive in `src`.
*/
async function build() {
reporter.info('Creating components');
const modules = meta.map(icon => {
const { source } = createIconComponent(icon.moduleName, icon.descriptor);
return {
moduleName: icon.moduleName,
filepath: icon.outputOptions.file.replace(/^es\//g, '').slice(0, -3),
filepath: icon.outputOptions.file
.replace(isWin ? /^es\\/g : /^es\//g, '')
.slice(0, -3),
source,
};
});
Expand All @@ -64,6 +69,7 @@ async function build() {
},
}`;

reporter.info('Bundling may take a while...');
const bundle = await rollup({
input: {
index: '__entrypoint__.js',
Expand Down Expand Up @@ -91,6 +97,7 @@ async function build() {
],
});

reporter.info('Writing out to files');
await Promise.all(
BUNDLE_FORMATS.map(({ format, dir }) => {
return bundle.write({
Expand All @@ -101,7 +108,11 @@ async function build() {
);
}

build().catch(error => {
// eslint-disable-next-line no-console
console.error(error);
});
build()
.then(() => {
reporter.success('Done!');
})
.catch(error => {
// eslint-disable-next-line no-console
console.error(error);
});