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

Improve output directory #120

Merged
merged 5 commits into from
Sep 26, 2017
Merged

Improve output directory #120

merged 5 commits into from
Sep 26, 2017

Conversation

zamotany
Copy link
Contributor

Closes #101

@codecov
Copy link

codecov bot commented Sep 26, 2017

Codecov Report

Merging #120 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #120      +/-   ##
==========================================
+ Coverage    97.5%   97.56%   +0.06%     
==========================================
  Files          19       19              
  Lines         361      370       +9     
  Branches       64       66       +2     
==========================================
+ Hits          352      361       +9     
  Misses          9        9
Impacted Files Coverage Δ
src/babel/preval-extract/utils.js 100% <100%> (ø) ⬆️
src/babel/preval-extract/extractStyles.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fe831c1...5b52f4a. Read the comment docs.

@@ -142,44 +207,45 @@ describe('preval-extract/extractStyles module', () => {

expect(fs.writeFileSync).toHaveBeenCalledTimes(1);
expect(fs.writeFileSync.mock.calls[0][0]).toEqual(
path.join(process.cwd(), 'A.css')
path.join(process.cwd(), '.linaria-cache/filename.css')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if we should display a warning, if the filename is used without single?

);
expect(fs.writeFileSync.mock.calls[1][1]).toMatch(
'.classname{color: #ffffff}\n.other{color: #000000}'
);
});

it('should overwrite if the file has changed', () => {
it('should overwrite if the tyles has changed', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: styles

: filename;
}

export function makeAbsolute(filename: string): string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong, but shouldn't path.resolve(filename) solve this?

cache: true,
extract: true,
single: false,
outDir: '.linaria-cache',
filename: 'styles.css',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we shift those defaults to function arguments?

export default function extractStyles(
  types: BabelTypes,
  program: NodePath<*>,
  currentFilename: string,
  options: {
    single?: boolean = false,
    filename?: string = 'styles.css',
    outDir?: string = '.linaria-cache',
    cache?: boolean = true,
    extract?: boolean = true,
  }
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we cannot.

The snippet you posted is invalid:

options: {
    single?: boolean = false,
    filename?: string = 'styles.css',
    outDir?: string = '.linaria-cache',
    cache?: boolean = true,
    extract?: boolean = true,
  }

Invalid syntax.

And besides:

function test(opts = { test: true }) { console.log(opts); }

test() // => { test: true }
test({ what: 'ever' }) // => { what: 'ever' }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still won't work.

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.
I think we could replace most of path.join(process.cwd(), name) with path.resolve(name).
Documentation says:

If after processing all given path segments an absolute path has not yet been generated, the current working directory is used.

@zamotany zamotany merged commit 15d7c80 into master Sep 26, 2017
@zamotany zamotany deleted the improve-output-directory branch September 26, 2017 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants