Unverified Commit 984ac96d authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

chore: remove old traces of `next/data` experiment (#20678)

This PR removes some left over traces of the `next/data` experiment, as it has been superseded by RSC.
parent dffb4713
import {
NodePath,
PluginObj,
types as BabelTypes,
} from 'next/dist/compiled/babel/core'
export default function ({
types: t,
}: {
types: typeof BabelTypes
}): PluginObj<any> {
return {
visitor: {
ImportDeclaration(path: NodePath<BabelTypes.ImportDeclaration>, state) {
const source = path.node.source.value
if (source !== 'next/data') return
const createHookSpecifier = path.get('specifiers').find((specifier) => {
return (
specifier.isImportSpecifier() &&
(t.isIdentifier(specifier.node.imported)
? specifier.node.imported.name
: specifier.node.imported.value) === 'createHook'
)
})
if (!createHookSpecifier) return
const bindingName = createHookSpecifier.node.local.name
const binding = path.scope.getBinding(bindingName)
if (!binding) {
return
}
binding.referencePaths.forEach((refPath) => {
let callExpression = refPath.parentPath
if (!callExpression.isCallExpression()) return
let args: any = callExpression.get('arguments')
if (!args[0]) {
throw callExpression.buildCodeFrameError(
'first argument to createHook should be a function'
)
}
if (!args[1]) {
callExpression.node.arguments.push(t.objectExpression([]))
}
args = callExpression.get('arguments')
args[1].node.properties.push(
t.objectProperty(
t.identifier('key'),
t.stringLiteral(state.opts.key)
)
)
})
},
},
}
}
...@@ -842,7 +842,6 @@ export default async function getBaseWebpackConfig( ...@@ -842,7 +842,6 @@ export default async function getBaseWebpackConfig(
'error-loader', 'error-loader',
'next-babel-loader', 'next-babel-loader',
'next-client-pages-loader', 'next-client-pages-loader',
'next-data-loader',
'next-serverless-loader', 'next-serverless-loader',
'noop-loader', 'noop-loader',
'next-plugin-loader', 'next-plugin-loader',
......
import babelLoader from './babel-loader/src/index' import { join } from 'path'
import hash from 'next/dist/compiled/string-hash'
import { basename, join } from 'path'
import * as Log from '../../output/log' import * as Log from '../../output/log'
import babelLoader from './babel-loader/src/index'
// increment 'o' to invalidate cache // increment 'o' to invalidate cache
// eslint-disable-next-line no-useless-concat // eslint-disable-next-line no-useless-concat
...@@ -149,17 +148,6 @@ const customBabelLoader = babelLoader((babel) => { ...@@ -149,17 +148,6 @@ const customBabelLoader = babelLoader((babel) => {
options.plugins.push(diallowExportAll) options.plugins.push(diallowExportAll)
} }
if (isServer && source.indexOf('next/data') !== -1) {
const nextDataPlugin = babel.createConfigItem(
[
require('../../babel/plugins/next-data'),
{ key: basename(filename) + '-' + hash(filename) },
],
{ type: 'plugin' }
)
options.plugins.push(nextDataPlugin)
}
// If the file has `module.exports` we have to transpile commonjs because Babel adds `import` statements // If the file has `module.exports` we have to transpile commonjs because Babel adds `import` statements
// That break webpack, since webpack doesn't support combining commonjs and esmodules // That break webpack, since webpack doesn't support combining commonjs and esmodules
if (source.indexOf('module.exports') !== -1) { if (source.indexOf('module.exports') !== -1) {
......
import { loader } from 'webpack'
import hash from 'next/dist/compiled/string-hash'
import { basename } from 'path'
const nextDataLoader: loader.Loader = function () {
const filename = this.resourcePath
return `
import {createHook} from 'next/data'
export default createHook(undefined, {key: ${JSON.stringify(
basename(filename) + '-' + hash(filename)
)}})
`
}
export default nextDataLoader
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment