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

Updates for Node 21 upgrade #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 1 addition & 31 deletions lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ var rewriteStyle = require('./style-rewriter')
var compileTemplate = require('./template-compiler')

// determine dynamic script paths
var hotReloadAPIPath = normalize.dep('vue-hot-reload-api')
var insertCSSPath = normalize.lib('insert-css')

var hasBabel = true
Expand Down Expand Up @@ -62,7 +61,6 @@ compiler.applyConfig = function (config) {
compiler.compile = function (content, filePath, cb) {
var isProduction = process.env.NODE_ENV === 'production'
var isServer = process.env.VUE_ENV === 'server'
var isTest = !!process.env.VUEIFY_TEST

// generate css scope id
var id = 'data-v-' + genId(filePath)
Expand Down Expand Up @@ -91,10 +89,7 @@ compiler.compile = function (content, filePath, cb) {

function mergeParts () {
// check whether script/template has changed
var prevParts = resolvedPartsCache[id] || {}
resolvedPartsCache[id] = resolvedParts
var scriptChanged = resolvedParts.script !== prevParts.script
var templateChanged = resolvedParts.template !== prevParts.template
Comment on lines -94 to -97
Copy link
Author

Choose a reason for hiding this comment

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

These vars were used by the hot reload code below and aren't referenced now.


var output = ''
var map = null
Expand Down Expand Up @@ -152,32 +147,7 @@ compiler.compile = function (content, filePath, cb) {
if (hasScopedStyle) {
output += '__vue__options__._scopeId = "' + id + '"\n'
}
// hot reload
if (!isProduction && !isTest && !isServer) {
output +=
'if (module.hot) {(function () {' +
' var hotAPI = require("' + hotReloadAPIPath + '")\n' +
' hotAPI.install(require("vue"), true)\n' +
' if (!hotAPI.compatible) return\n' +
' module.hot.accept()\n' +
// remove style tag on dispose
(style && !options.extractCSS
? ' module.hot.dispose(__vueify_style_dispose__)\n'
: '') +
' if (!module.hot.data) {\n' +
// initial insert
' hotAPI.createRecord("' + id + '", __vue__options__)\n' +
' } else {\n' +
// update
(scriptChanged
? ' hotAPI.reload("' + id + '", __vue__options__)\n'
: templateChanged
? ' hotAPI.rerender("' + id + '", __vue__options__)\n'
: ''
) +
' }\n' +
'})()}'
}

if (map) {
output += '\n' + convert.fromJSON(map.toString()).toComment()
}
Expand Down
27 changes: 11 additions & 16 deletions lib/compilers/sass.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ var path = require('path')
var ensureRequire = require('../ensure-require.js')

module.exports = function (raw, cb, compiler, filePath) {
ensureRequire('sass', 'node-sass')
var sass = require('node-sass')
ensureRequire('sass', 'sass')
Copy link
Author

Choose a reason for hiding this comment

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

I don't know if this is actually necessary, but I didn't want to rewrite too much right now.

var sass = require('sass')

var sassOptions = assign({
data: raw,
Expand All @@ -28,18 +28,13 @@ module.exports = function (raw, cb, compiler, filePath) {
? sassOptions.includePaths.concat(paths)
: paths

sass.render(
sassOptions,
// callback for node-sass > 3.0.0
function (err, res) {
if (err) {
cb(err)
} else {
res.stats.includedFiles.forEach(function (file) {
compiler.emit('dependency', file)
})
cb(null, res.css.toString())
}
}
)
try {
let res = sass.renderSync(sassOptions)
Copy link
Author

Choose a reason for hiding this comment

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

render is deprecated and not recommended if you're using sass via npm. I replaced it with renderSync, which takes the same LegacyOptions param. renderSync returns a result or throws an error, so I wrapped everything in a try..catch to handle the callbacks.

res.stats.includedFiles.forEach(function (file) {
compiler.emit('dependency', file)
})
cb(null, res.css.toString())
} catch (err) {
cb(err)
}
}
Loading