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

import code snippet fail(BUG #1151 The situation still exists) #1297

Closed
1 task done
jiaming743 opened this issue Feb 15, 2019 · 7 comments
Closed
1 task done

import code snippet fail(BUG #1151 The situation still exists) #1297

jiaming743 opened this issue Feb 15, 2019 · 7 comments

Comments

@jiaming743
Copy link

jiaming743 commented Feb 15, 2019

  • I confirm that this is a issue rather than a question.

Bug report

BUG #1151

According to @shigma 's advice

I removed ":"

myVuePressProject/node_modules/vuepress/lib/markdown/snippet.js#27

Before

const filename = rawPath.split(/[{:\s]/).shift()

After

const filename = rawPath.split(/[{\s]/).shift()

It still shows Not found: E

What's more

I tried console.log(content) and the contents of the file can be read normally.

myVuePressProject/node_modules/vuepress/lib/markdown/snippet.js#28

const content = fs.existsSync(filename) ? fs.readFileSync(filename).toString() : 'Not found: ' + filename

Version

[email protected]

Steps to reproduce

What is expected?

show codes what I imported

What is actually happening?

show me Not found: E

Other relevant information

  • Your OS: Windows 10
  • Node.js version: 10.13.0
  • Browser version: Chrome 70.0.3538.102
  • Is this a global or local install? * ([email protected]) and local ([email protected])
  • Which package manager did you use for the install? yarn
@shigma
Copy link
Collaborator

shigma commented Feb 15, 2019

Really wield. After first running, any change to the file you mentioned will be of no effect, even if you replace line.28 with something like const content = 'Hello World'. But if you change the file before first usage, the code snippet will run as expected.

I think it's a problem with cache system.

If it is, don't be worried. Just wait for an update on v0.x branch and everything will be ok.

@shigma
Copy link
Collaborator

shigma commented Feb 15, 2019

@ulivz Do I also need to send a PR to v0.x branch, something like #1236 ?

@ulivz
Copy link
Member

ulivz commented Feb 16, 2019

@shigma Contribution welcome!

@shigma
Copy link
Collaborator

shigma commented Feb 17, 2019

@ulivz A release of 0.x may solve this issue, any plans?

@ulivz
Copy link
Member

ulivz commented Feb 17, 2019

Released 0.14.9, @jiaming743 could you try the latest version?

@jiaming743
Copy link
Author

jiaming743 commented Feb 18, 2019

👍The problem has been solved. @ulivz @shigma

But I found a situation: import test.js in test.md, then change the contents of test.js and press 'ctrl+s', the page has not changed after compile automatically. Then I switch to test.md and press 'ctrl+s', the page changed after compile automatically again.

It seems that: changes to the imported file will not trigger the recompilation of the code snippet, you need to re-save the 'test.md' to trigger the code snippet compilation.

Steps to reproduce

test.js

export default {
    // this is a test file.
}

test.md

<<< @/dirpath/test.js

current code snippet

export default {
    // this is a test file.
}

setp1

change test.js

export default {
    // test test test...
}

press 'ctrl+s' in test.js

compile automatically...

current code snippet

export default {
    // this is a test file.
}

No change

setp2

switch to test.md(No edits)

press 'ctrl+s' in test.md

compile automatically...

current code snippet

export default {
    // test test test...
}

changed

@shigma
Copy link
Collaborator

shigma commented Feb 18, 2019

It's because imported codes are not treated as dependencies at present, so changes to those files will not trigger hmr......

It's a long story. I have openned a new issue about that.

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

No branches or pull requests

3 participants